开发者

disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

I am using Ms Office Interop assemblies to create a MS Project file. To save the file created, I am using FileSaveAs m开发者_如何学编程ethod and it prompts a message saying that if you want to replace the existing file. I want to suppress the message, and I didn't find any parameter in FileSaveAs method for this purpose. Any Idea on this? I'am using C# as my programming language.


I ran into this issue when working with Excel Interop. The best I've been able to find is to disable all Office alerts, like this:

Microsoft.Office.Interop.MSProject.Application msProjectApp = new Microsoft.Office.Interop.MSProject.Application();
msProjectApp.DisplayAlerts = false;


Never double dot COM objects, as they will not be released and this will leave excel open on your server. Unfortunately I have crashed servers because of this.

private void InitialiseExcel()
{
    if (excelApp == null)
        excelApp = new Excel.Application();
    // Turn off User Prompts
    excelApp.DisplayAlerts = false;
    // Turn off screen updating so we do not get flicker
    var app = excelApp.Application;
    app.ScreenUpdating = false;
    // Specifies the state of the window;
    excelApp.WindowState = Excel.XlWindowState.xlMinimized;
    Marshal.ReleaseComObject(app);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜