Returns the property value as DateTime in UTC.
[Visual Basic]Public Function ToDateTime() As
Date Remarks
Throws an exception if the property type is not DateTime.
Microsoft Word stores only the date part (no time) for custom date properties.
Example
Retrieves a custom document property by name.
[C#]
Document doc = new Document(MyDir + "Properties.doc");
DocumentProperty prop = doc.CustomDocumentProperties["Authorized Date"];
if (prop != null)
{
Console.WriteLine(prop.ToDateTime());
}
else
{
Console.WriteLine("The document is not authorized. Authorizing...");
doc.CustomDocumentProperties.Add("AuthorizedDate", DateTime.Now);
}[Visual Basic]
Dim doc As Document = New Document(MyDir & "Properties.doc")
Dim prop As DocumentProperty = doc.CustomDocumentProperties("Authorized Date")
If Not prop Is Nothing Then
Console.WriteLine(prop.ToDateTime())
Else
Console.WriteLine("The document is not authorized. Authorizing...")
doc.CustomDocumentProperties.Add("AuthorizedDate", DateTime.Now)
End IfRetrieves the types and values of the custom document properties.
[C#]
Document doc = new Document(MyDir + "Properties.doc");
foreach (DocumentProperty prop in doc.CustomDocumentProperties)
{
Console.WriteLine(prop.Name);
switch (prop.Type)
{
case PropertyType.String:
Console.WriteLine("It's a string value.");
Console.WriteLine(prop.ToString());
break;
case PropertyType.Boolean:
Console.WriteLine("It's a boolean value.");
Console.WriteLine(prop.ToBool());
break;
case PropertyType.Number:
Console.WriteLine("It's an integer value.");
Console.WriteLine(prop.ToInt());
break;
case PropertyType.DateTime:
Console.WriteLine("It's a date time value.");
Console.WriteLine(prop.ToDateTime());
break;
case PropertyType.Double:
Console.WriteLine("It's a double value.");
Console.WriteLine(prop.ToDouble());
break;
case PropertyType.Other:
Console.WriteLine("Other value.");
break;
default:
throw new Exception("Unknown property type.");
}
}[Visual Basic]
Dim doc As Document = New Document(MyDir & "Properties.doc")
For Each prop As DocumentProperty In doc.CustomDocumentProperties
Console.WriteLine(prop.Name)
Select Case prop.Type
Case PropertyType.String
Console.WriteLine("It's a string value.")
Console.WriteLine(prop.ToString())
Case PropertyType.Boolean
Console.WriteLine("It's a boolean value.")
Console.WriteLine(prop.ToBool())
Case PropertyType.Number
Console.WriteLine("It's an integer value.")
Console.WriteLine(prop.ToInt())
Case PropertyType.DateTime
Console.WriteLine("It's a date time value.")
Console.WriteLine(prop.ToDateTime())
Case PropertyType.Double
Console.WriteLine("It's a double value.")
Console.WriteLine(prop.ToDouble())
Case PropertyType.Other
Console.WriteLine("Other value.")
Case Else
Throw New Exception("Unknown property type.")
End Select
Next propSee Also
DocumentProperty Class | Aspose.Words.Properties Namespace