'Office.Interop.Word - app.DisplayAlerts = WdAlertLevel.wdAlertsNone; Not Disabling Alerts
I'm trying to disable read-only alerts when opening word files in C#. I initially tried app.DisplayAlerts = false
. This did not work and I believe it's because I have a newer version of word. Now, using word.DisplayAlerts = WdAlertLevel.wdAlertsNone
does not disable the popups either. I'm not sure why, as I've seen several StackOverflow posts indicating that it should. Here's my code (part of a method to convert doc to docx):
Application app = new Application();
app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
var sourceFile = new FileInfo(path);
var document = app.Documents.Open(sourceFile.FullName);
string newFileName = sourceFile.FullName.Replace(".doc", ".docx");
document.SaveAs2(newFileName, WdSaveFormat.wdFormatXMLDocument,
CompatibilityMode: WdCompatibilityMode.wdWord2010);
app.ActiveDocument.Close();
GC.Collect();
GC.WaitForPendingFinalizers();
app.Quit();
app = null;
GC.Collect();
Any suggestions?
Solution 1:[1]
Have you considered opening the document readonly? That prevents the readonly alert. You have to pass the readonly:=true to the document.open method.
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 | Boeryepes |