Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi..

i have Code to Update Custom Variables using OpenXml SDK in C#
to Update custom variables in document i have added

C#
using (_objDoc = WordprocessingDocument.Open(szFileName, true))
{
   DocumentSettingsPart settingsPart =    _objDoc.MainDocumentPart.GetPartsOfType<DocumentSettingsPart>().First();
  UpdateFieldsOnOpen updateFields = new UpdateFieldsOnOpen();
  updateFields.Val = new DocumentFormat.OpenXml.OnOffValue(true);
  settingsPart.Settings.PrependChild<UpdateFieldsOnOpen>(updateFields);
  settingsPart.Settings.Save();
}


when i open world document i'm getting following prompt.
"This document contains fields that may refer to other files. Do you want to update the fields in this document?"

VB
With Options
        .UpdateFieldsAtPrint = True
        .UpdateLinksAtPrint = True
    End With
    For Each l_section In ActiveDocument.Sections
        For Each l_headerfooter In l_section.Headers
        l_headerfooter.Range.Fields.Update
    Next l_headerfooter
    For Each l_headerfooter In l_section.Footers
        l_headerfooter.Range.Fields.Update
    Next l_headerfooter
    Next l_section
    ActiveDocument.Fields.Update

i have used above Macro to update Custom variable on client machine but it's not a convenient option for me as i need to updated macro on each machine.

how i can avoid/hide this prompt .
Posted
Updated 31-Jul-15 18:03pm
v5
Comments
Maciej Los 9-Jun-15 13:35pm    
Could you be so kind and share a bit more of code?
Kannan Subramaniam 3-Aug-15 7:10am    
try to open the created word file in the openxml developer tool and validate the word file. It will show the appropriate error messages.
Lio 1-Jul-18 22:25pm    
I have the same problem. I want to avoid/hide with YES on this prompt? How this can be done?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900