Free Support Forum - aspose.com

Renaming Merge Fields Matching Problem (and possible solution)

Following the guide on:
http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/rename-merge-fields.html

I was having an issue with some word documents and not being able to match the field names for replacement. I added some debug code and found the following:

Debug Code:
response.write("Name: " & mergeField.Name & "
")

Result:
Name: «Name»

Fix:
replace(replace(CStr(mergeField.Name),"«",""),"»","")

Is there a reason that the mergefields have «» in their names? Is this consistant? Will my fix be good enough, or do you forsee some issues with it?


This message was posted using Page2Forum from Rename Merge Fields - Aspose.Words for .NET and Java

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

Thanks for your request. I can’t reproduce this issue on my side. I used the following code for testing.

// Specify your document name here.

Document doc = new Document(Server.MapPath("in.doc"));

// Select all field start nodes so we can find the merge fields.

NodeList fieldStarts = doc.SelectNodes("//FieldStart");

foreach (FieldStart fieldStart in fieldStarts)

{

if (fieldStart.FieldType == FieldType.FieldMergeField)

{

MergeField mergeField = new MergeField(fieldStart);

Response.Write("Name: " + mergeField.Name + "
"
);

}

}

Could you please attach your document for testing? I wil investigate this problem and try to help you.

Best regards.

Here is the file.

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

Thanks for additional information. But it seems the attached document does not contain merge fields at all. Please check your document.

Best regards.

Sorry,

Try this one.

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

Thanks for additional information. I still can’t reproduce this issue on my side. I used MergeField class from here.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/rename-merge-fields.html

Maybe you translated something incorrectly to VB. I tried to translate this class to VB myself. Please try using the attached code.

Best regards.