We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words Error : String was not recognized as a valid DateTime

I am testing the Aspose.Words with our existing Word Document. which we are executing them thru MsWord. We want to move to aspose. While executing the existing document thru Aspose.Words, i am getting the following message " String was not recognized as a valid Date time". But in Msword it works. I am guessing, the mergefield has the format as “MMMM d, yyyy”, but the data is “12/22/2007”. Msword ignores the field and leaves the empty value for that merge field, but aspose throwing an error. I want to ignore this field and leave the empty value for that.
How can i do this?

Thank you for your interest in Aspose.Words.
Please provide the test document and the code sample operating on it. We’ll investigate the issue and try to help you.

I am sorry. It was not that problem. Aspose throws an error when it tries to format the Empty data to date time. In table fieldtype is char(10), not datetime. Its not a required field, so it contains empty string.
Is there any flag setting for this?

From you explanation I see that you perform mail merge and some empty string is converted to date/time. This gives an exception and you’d like just to ignore the error, wouldn’t you? Field type is not date but during mail merge it is tried to be converted to date. This looks like a logical error.
Please provide materials to reproduce this. Aspose.Words has many places where dates are parsed and errors might happen. We need to investigate your exact case to help you effectively.

Yes. Mergefield has the date format.
{ MERGEFIELD MeetingDate \@ "MMMM d, yyyy" \* MERGEFORMAT }
DataTable has the table with columnname “MeetingDate” as Char(10).
I am just trying the simple mail merge with single record. Mail merge is getting failed when MeetingDate is empty.
Here attached the sample document which i am using for mail merge.

Thank you for additional information. I think that you can try using the following code as a workaround.

public void Test035()
    Document doc = new Document(@"Test035\in.doc");
    // Prepare data
    string[] names = { "MeetingDate" };
    string[] values = { "12/22/2007" };
    // Add MergeField event handler
    doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField035);
    // Execute mailmerge
    doc.MailMerge.Execute(names, values);
    // Save document
void MailMerge_MergeField035(object sender, MergeFieldEventArgs e)
    if (e.FieldName == "MeetingDate")
        DateTime date;
        // Check if string is valid date
        if (!DateTime.TryParse(e.FieldValue.ToString(), out date))
            e.Text = string.Empty; //ignore field

I hope this helps.
Best regards.

Thanks for your response. I guess that will help me. Anyway i hv to look up for some workaround to avoid the Fieldname verification. Because lof of columns has the DateTime type.
Let me play around with MergeEventHandler for this.