'How can I get rid of MS Word 2019 security dialogs when updating word function fields via C#?
I have a word document (.docx) where I'm inserting URIs to images in field functions. To update those fields in the document I'm using C# and the MS word interop functionalities. When I update those fields (which is manually pressing F9 in Word I think) I get the following dialogue box which I have to confirm manually:
An excerpt of my code looks like the following:
w = new Microsoft.Office.Interop.Word.Application();
w.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
w.ScreenUpdating = false;
...
oDoc.MailMerge.Application.ActiveDocument.Fields.Update();
The last line is the crucial one which triggers the security dialogue because if the images URIs. Everything works as intended when I confirm the dialogue. The images load correctly and there are no other pitfalls. How can I get rid of this security notice?
What I tried so far:
- Updating my word installation and lower security threshholds (such as enabling macros and adding safe space location in the TrustCenter
- As you can see I also tried to disable
DisplayAlertsprogrammatically how ever it does have no impact it seems.
I understand that this is a valid security concern and that MS office tries to prohebit those actions. How ever is there any way I could get rid of the dialogue? Either via configurating my MS Word in such a way or programmatically disable the security policy (I doubt that this is possible)? I also have to confirm the security notice when I'm updating the fields manually via MS Word.
I also read about that I could sign my application which performs the field updates. Would the signing in the end mean that I would get rid of the dialogue because the document and the application is trusted by MS Word/Office?
Any advices or hints are appreciated.
Solution 1:[1]
The Word object model doesn't provide anything for that. You can manually change settings under Privacy Options, select or clear Check Microsoft Office documents that are from or link to suspicious Web sites check box. See Enable or disable security alerts about links and files from suspicious websites for more information.
I believe all Word options are stored in the windows registry, so you could use any tool for monitoring changes such as https://docs.microsoft.com/en-us/sysinternals/.
Also there was a bug in the product, see How do I disable "Microsoft Word Security Notice" pop-up for more information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Astafiev |

