Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 method 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.

like image 320
Elangovan Avatar asked Jul 29 '10 08:07

Elangovan


2 Answers

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;
like image 104
dotNetkow Avatar answered Oct 18 '22 05:10

dotNetkow


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);
}
like image 25
tyler_mitchell Avatar answered Oct 18 '22 06:10

tyler_mitchell