I''m getting this exception, System.Runtime.InteropServices.ExternalException: Can not create compound file, when I do a .SaveAS(filename) on a workbook. This is from a .NET Web app. Has anyone else had this problem?
This generally happens when you already have an Excel file open with the same name. For example, if you have a file called "Sample.xls" open and you try to overwrite that file, then you will get this "cannot create compound file" exception. If this is not the case, could you please provide more information or provide a sample if possible. Thanks.
>I''m getting this exception, System.Runtime.InteropServices.ExternalException: Can not create compound file, when I do a .SaveAS(filename) on a workbook. This is from a .NET Web app. Has anyone else had this problem?
AdministratorDecember 14, 2005 03:18 PM UTC
I am getting the same error message. Actually, I am trying to overwrite an existing file. But the existing file is already opened.
How should I handle or catch this exception?
Can not create compound file.
at Syncfusion.ExcelRW.IO.Stream.StgStream.CreateStorage(String fileName)
at Syncfusion.ExcelRW.Implementation.WorkbookImpl.CreateOrOpenStorage(String path)
at Syncfusion.ExcelRW.Implementation.WorkbookImpl.SaveAs(String FileName, ExcelSaveType saveType)
at Syncfusion.ExcelRW.Implementation.WorkbookImpl.SaveAs(String FileName)
AdministratorDecember 15, 2005 12:59 PM UTC
Here is some sample code to check for an excel file that already exists and is open by excel and also to prompt the user to save their changes to a different file before we overwrite it
catch (System.Runtime.InteropServices.ExternalException ex)
if(ex.ErrorCode == -2147287007)
MessageBox.Show("The file that you are trying to create is already open","File is Open");
Please let me know if you have any questions.
AdministratorDecember 15, 2005 03:32 PM UTC
It worked. One more question, what if the user wants to overwrite already opened file.
Catch ex As System.Runtime.InteropServices.ExternalException
If ex.ErrorCode = -2147287007 Then
If MessageBox.Show("The file sample.xls is already opened. Are you sure you want to overwrite it?","", ) = YES Then
''Overwrite existing opened file
AdministratorDecember 15, 2005 08:21 PM UTC
I am afraid this would not be possible since there seems to be no way overwrite any file that is locked by another application.
>It worked. One more question, what if the user wants to overwrite already opened file.
>Catch ex As System.Runtime.InteropServices.ExternalException
> If ex.ErrorCode = -2147287007 Then
> If MessageBox.Show("The file sample.xls is already opened. Are you sure you want to overwrite it?","", ) = YES Then
> ''Overwrite existing opened file
> End If
AdministratorDecember 16, 2005 06:46 PM UTC
No problem! I just wanted to know, just in case users would ask for something like that.
ISIchiro SugimotoMarch 10, 2008 11:15 AM UTC
I'm using Essential Studio 184.108.40.206, and the user of my application met the same System.Runtime.InteropSevices.ExternalException in the IWorkbook.SaveAs(string) method. The stacktrace of the exception is as follows:
I tried to reproduce the issue, to overwrite the already existing Excel file which is opened. Then System.IO.IOException, not System.Runtime.InteropSevices.ExternalException, was thrown. The stacktrace is as follows:
What is the difference of the condition in which these exceptions are thrown?
AdministratorMarch 13, 2008 10:46 AM UTC
Thank you for your update.
Please try to send us the sample and the file in which this exception is reproduced so that we could sort out the cause of the issue and provide you a solution?
Also please provide the below details: 1. Sytem configuration 2. Office version
DHDennis HoranJuly 23, 2008 02:25 PM UTC
I just received this same error message in a .NET application, where the file was not opened. But, the IIS_WPG user group did not have write permissions to the directory where I was saving. I added the permissions and then it worked fine.
I assume that even if you have a windows application, you'll need to make sure that the user has write permissions to the directory.
Hope this helps.
Yavanaarasi GJuly 28, 2008 03:35 AM UTC
Thanks for sharing your ideas.
Please let me know if you have any other concerns.
ISIchiro SugimotoAugust 18, 2008 09:04 AM UTC
I'm sorry for my delay response.
[1. Sytem configuration] Microsoft Windows XP Professional Version 2002 Service Pack 2
IBM Corporation Intel(R) Pentium(R) M processor 2.26GHz 2.26GHz, 2.00 GB RAM
[2. Office version] Microsoft Office Professional Edition 2003
And, this issue seems to occur only with specific (i.e. not every) exporting data.