Prinsu
Prinsu

Reputation: 31

Saving to excel file causes error in c# windows

Here is the code:

try
{
    if (File.Exists("c:\\Reports\\" + fileName))
    {
        File.Delete("c:\\Reports\\" + fileName);
    }
    _book.SaveAs("c:\\Reports\\" + fileName, Excel.XlFileFormat.xlWorkbookNormal,
                   null, null, false, false, Excel.XlSaveAsAccessMode.xlShared,
                   false, false, null, null, null);
}
catch (Exception ee)
{
    throw ee;
}

On saving to excel format . I have got the following error as follows..

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I am using MS Office version 2000.

Dll using is Interop.excel 1.4.0.0

Using Visual studio 2008 + c# console application

Upvotes: 2

Views: 687

Answers (1)

Brijesh Mishra
Brijesh Mishra

Reputation: 2748

use _book.SaveCopyAs("c:\Reports\" + fileName)

Upvotes: 2

Related Questions