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

Free Support Forum - aspose.com

Update FILENAME field on save

I have to open a word docx do some modifications and save with a different name. The problem is that I have FILENAME field all over in the document and on save aspose cannot update this field.

How can I update this field?

Hi Peter,

Thanks for your inquiry. Aspose.Words does not know what will be the name of the output document, because you can specify any file name you like. So FILENAME field should be updated upon saving the document. We had already logged this feature as WORDSNET-2723 in our issue tracking system. We will update you via this forum thread once this feature is available.

You can use following code snippet as a workaround.

<span style=“font-family: “Courier New”; color: rgb(43, 145, 175);” lang=“EN-GB”>Document<span style=“font-family: “Courier New”;” lang=“EN-GB”> doc = new
Document(MyDir + “in.docx”);<o:p></o:p>

SetFileName("AsposeOut.docx", doc);

doc.Save(MyDir + "AsposeOut.docx");

public void SetFileName(string filename, Document _document)

{

foreach (FieldStart fieldStart in _document.GetChildNodes(NodeType.FieldStart, true))

{

switch (fieldStart.FieldType)

{

case Aspose.Words.Fields.FieldType.FieldFileName:

Run filenameMergeformat = (Run)fieldStart.NextSibling; // Text=FILENAME \* MERGEFORMAT

FieldSeparator fieldSeparator = (FieldSeparator)filenameMergeformat.NextSibling; // Separator

Run filenameCurrentValue = (Run)fieldSeparator.NextSibling; // Run Text=

filenameCurrentValue.Text = filename;

break;

default:

break;

}

}

}


Is there any news on this feature being implemented in the near future?

Doesn’t seem all to difficult to me :).
Hi there,

Thanks for your inquiry.

I am afraid this feature has now been postponed till a later date due to some other important issues and new features. We will inform you as soon as there are any further developments.

We apologize for your inconvenience.

A post was split to a new topic: Update FILENAME upon saving the document