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

Free Support Forum - aspose.com

Aspose words preserve format Ref Field


I am building a clean document for my client, for that reason I want to remove SET and REF once I am done processing the document.

I am able to remove SET and REF but I am not able to preserve the format of REF field.

Here, I have attached my test project for your reference. I am using version of Aspose.Words.dll

Thanks for your help in advance.


Hi John,

Thanks for your inquiry. Please use the FieldsHelper.ConvertFieldsToStaticText method to achieve your requirement. Please check the code of FieldsHelper class in the following article:

// Your code...

// ....

DataSet ds = new DataSet();


Document doc = new Document(dataDir + "TableSet.docx");


// Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to static text.

FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldRef);

//Remove SET fields

NodeCollection starts = doc.GetChildNodes(NodeType.FieldStart, true);

foreach (FieldStart start in starts)


if (start.FieldType == FieldType.FieldSet)






doc.Save(dataDir + "TableSet - Output.docx");

Thanks Tahir! That was worked.

Hi John,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.