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

Free Support Forum - aspose.com

Updating autodate fields in a table

Hi Team,
I am using Aspose to remove the autodate field from my word document while leaving the date in place. This seems to work perfectly for me except when the AutoDate field is found in a table. When the code finds the Autodate field in a table it removes the autodate function but does not leave the date. Is there a way of Leaving\Adding the AutoDate text to the table.
Thanks in advance
Garry

Sample Code
foreach (FieldStart start in starts)
{
if (start.FieldType == FieldType.FieldDate)
{

Node node = start;

string fieldCode = “”;

while (node.NodeType != NodeType.FieldEnd)
{

if (node.NodeType == NodeType.Run)
{

fieldCode += ((Run)node).GetText();

}

node = node.NextSibling;

}
dateFieldSeparators.Add(node);
node = node.NextSibling;
Match match = Regex.Match(fieldCode, @".?\@\s""(?.*?)""");
dateFormat = match.Groups[“dateformat”].Value;
date = DateTime.UtcNow.ToString(dateFormat, CultureInfo.CurrentCulture);
dates.Add(date);

}


if (start.FieldType == FieldType.FieldDate || start.FieldType == FieldType.FieldTime)
{

dateStarts.Add(start);
//Move cursor to the field start position
builder.MoveTo(start);

//Insert [AutoDate] text
builder.Write(date);


}

}

//Now we should remove Date and Time fields

foreach (FieldStart start in dateStarts)
{

Node currentNode = start;

while (currentNode.NodeType != NodeType.FieldEnd)
{

currentNode = currentNode.NextSibling;

currentNode.PreviousSibling.Remove();

}

currentNode.Remove();

}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please attach your document for testing? I will investigate the problem and provide you more information.

Best regards.

Hi alexey,

Please find document attached

Thanks
Garry

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. The problem occurs because there is TIME field instead DATE field. You can easy solve the issue using the following code snippet:

foreach (FieldStart start in starts)

{

if (start.FieldType == FieldType.FieldDate || start.FieldType == FieldType.FieldTime)

{

Hope this helps.

Best regards.

This worked perfect.
Thanks
Garry