Unable to update or Edit Autotext

Hi,

For a particular Document we are unable to Update autotext field.

We have Autotext field in a Document for Date and name ,where this both Autotext is not Working(Cannot update or edit it programmatically).

Even Alt+f9 is not working for it, It stays ideal.

Note: For other Documents It is Working good. Issue is Specific to particular Document.
and in the same Document if i add a new Autotext Manually and if i try then it Works, the existing autotext Doesn’t Work.

We use below sample code to check whether autotext is present in Document. It skips this condition for that specific Document alone.

if (field.Type.Equals(Aspose.Words.Fields.FieldType.FieldAutoText))

@NanthiniSenthil123 Could you please attach the problematic document here for testing? It is difficult to tell what is going wrong without it. We will check the issue and provide you more information.

autotextissue.docx (22.5 KB)

Here I have uploaded the document for which we are facing Autotext issue .Can you please help.Sample code i have already share.

@NanthiniSenthil123 Thank you for additional information. I have checked your document. You have mentioned that you are interested in autotext items that represent name and date. But there name and date in your document are represented as a simple text:

<w:p w14:paraId="09D18FE8" w14:textId="77777777" w:rsidR="00BA0D0C" w:rsidRPr="008C2D5A" w:rsidRDefault="00910514" w:rsidP="00573EFF">
	<w:pPr>
		<w:pStyle w:val="Header"/>
		<w:jc w:val="right"/>
		<w:rPr>
			<w:color w:val="0000FF"/>
		</w:rPr>
	</w:pPr>
	<w:r>
		<w:rPr>
			<w:color w:val="0000FF"/>
		</w:rPr>
		<w:t>MidMichigan Health</w:t>
	</w:r>
</w:p>
<w:p w14:paraId="478A7925" w14:textId="310F7B0E" w:rsidR="00BA0D0C" w:rsidRDefault="00910514" w:rsidP="00573EFF">
	<w:pPr>
		<w:pStyle w:val="SCH-BP"/>
		<w:jc w:val="right"/>
	</w:pPr>
	<w:r>
		<w:t>Effective Date:  06/15/2022</w:t>
	</w:r>
</w:p>


So, Aspose.Words behaves properly.

Can you please help me how you determine that it is simple text.

image.png (29.4 KB)

As mentioned in above scrrenshot i tried .will be grateful if i come to know hoe to determine it as simple text.

@NanthiniSenthil123 You can press Alt+F9 to toggle field codes in MS Word to check whether text is inserted as simple text or as a field.

Thank you That helps…

Hi,

For a Word document With Autotext we are having value while opening it, but when we press CTRL+p to print or when we try to change it as PDF , the autotext changes as “Error AutoText Not Defined”.

Here i have attached Screenshot and Document,Can you help us .


AutoText(CTRL+P).docx (23.7 KB)

@NanthiniSenthil123 The problem occurs because MS Word automatically updated fields before printing. In your case the fields are in the header and disabling Update fields before printing (File>Options>Display and uncheck the “Update fields before printing”) will not help, since header/footer fields are always updated.
In your case, you should either lock or unlink (replace with static text) the fields. Select the AUTOTEXT fields in your header and then Ctrl+F11 to Lock the fields, or Ctrl+Shift+F9 to Unlink them.

Thank you ,That was helpful.
Can you please help me how to implement lock and unlink Autotext Programmatically

@NanthiniSenthil123 Sure, please see the following code that demonstrates how you can unlink or lock AUTOTEXT fields:

Document doc = new Document(@"C:\Temp\in.docx");

foreach (Field f in doc.Range.Fields)
{
    // Check the type of the field.
    if (f.Type == FieldType.FieldAutoText)
    {
        // Unlink field.
        f.Unlink();

        // If you need to lock field, comment the above line and uncomment the below line of code.
        // f.IsLocked = true;
    }
}

doc.Save(@"C:\Temp\out.docx");