Error 'Exception from HRESULT: 0x800A03EC' when saving an excel file in C#-ASP.NET 2

vipin_pc

Newcomer
Joined
Nov 26, 2008
Messages
4
Hi All,

In one the intranet sites which I have developed, i'm creating an excel file from C#.Net 2005-ASP.NET 2.0

application. In my local machine which runs on Windows XP the application works perfectly, but when I try to run

the application in windows 2008 server machine it throws an exception.

'Exception from HRESULT: 0x800A03EC'

What is running in the windows 2008 server machine is the published version of my application. I have all the

required dlls and other application dependency files in the bin folder including Interop.Excel.dll and

Interop.Microsoft.Office.Core.dll.

The windows 2008 server machine has MS Office 2003 version installed. I have also configured DCOM in this machine.

Here is my code
C#:
            string fileName = "", strSaveFileAs = "";//To Save the File Name of the Excel File
            ItemMaster itemInfo;        
            Excel.Application xlApp = new Excel.Application();//initialise Xl app
            Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(true);
            object worksheet = xlWorkBook.ActiveSheet;// set work sheet
            object objMissing = System.Reflection.Missing.Value;                      
            if (arList.Count > 0)
            {
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1,1] = "SINO";
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 2] = "ItemGroupName";
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 3] = "ItemCode";
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 4] = "ItemName";
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 5] = "QTY";
                ((Excel.Worksheet)xlApp.ActiveSheet).Cells[1, 6] = "Rate";              
 
                int SINo = 0;// To Show Serial No in excel.                
                for (int iRows = 1; iRows <= arList.Count; iRows++)
                {
                    itemInfo = new ItemMaster();
                    itemInfo = (ItemMaster)arList[SINo];                    
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 1] = (SINo + 1).ToString();
                    //Here GroupId actually contains group name                    
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 2] = itemInfo.GroupID.ToString();
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 3] = itemInfo.ItemCode.ToString();
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 4] = itemInfo.ItemName.ToString();
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 5] = "";
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 6] = itemInfo.Rate.ToString();
                    ((Excel.Worksheet)xlApp.ActiveSheet).Cells[iRows + 1, 7] = "";
                    ((Excel.Worksheet)worksheet).Columns.AutoFit();  //format                  
                    xlApp.ScreenUpdating = true;
                    SINo++;
                }
                /* FileName format of xls is: QuoteNo_CustomerName_Date*/
                strSaveFileAs = txtCode.Text + "_" + ddlCustomer.SelectedItem.ToString() + "_" +  txtDate.Text;     

           
                string filePath = Server.MapPath("..//Sales//Quote/");                
                fileName = filePath + "QuoteFile" + ".xls";
                if (File.Exists(fileName))
                    File.Delete(fileName);
                  //Save file in the Location 'fileName'
                xlWorkBook.SaveAs((object)(fileName), objMissing, objMissing, objMissing, objMissing, objMissing, 

Excel.XlSaveAsAccessMode.xlNoChange, objMissing, objMissing, objMissing, objMissing, objMissing);
"Exception from HRESULT: 0x800A03EC" exception is thrown when the line of code

xlWorkBook.SaveAs((object)(fileName), objMissing, objMissing, objMissing, objMissing, objMissing, Excel.XlSaveAsAccessMode.xlNoChange, objMissing, objMissing, objMissing, objMissing, objMissing); is executed.

Looking forward to hear from you soon.
 
Last edited by a moderator:
Is the version of Excel the same on both the server and your PC? Does the application have permissions to write to the folder on the server?

One other thing to check is if it works using an absolute path rather than with the ..// bit in, IIS 7 disbales parent paths by default (which is a good thing really) - you could always re-enable it with
Code:
appcmd set config -section:asp -enableParentPaths:true
however this is introducing a potential security risk.
 
To your questions
1. Is the version of Excel the same on both the server and your PC?

Yes both are having MS Office 2003

2. Does the application have permissions to write to the folder on the server?

Could you please explain this question little more?

In case i want to enable "..//", where should i execute this code "appcmd set config -section:asp -enableParentPaths:true"
 
The exact error i'm getting is
System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
 
Regarding the permissions you will need to check on the IIS manager tool what application pool the website is running under and then the user account the application pool uses - this user will then need the ability to read and write to the folder containing your application.

To run the command thing just open a command prompt as administrator and cd to to the %systemroot%/System32 folder and then just type it in.
 
I checked the user accounts and also permissions. Its NETWORK SERVICES and I have given full permission. I'm attaching an image(screen shot) with this. I have also added IUSRS, INTERACTIVE and SYSTEM accounts

These accounts also have DCOM "Access Permissions" and "Launch and Activation Permissions"

I'm sorry that in my thread i have not mentioned that the Windows 2008 Server is trial version.
 

Attachments

Can any body tell me how did you resolve the issue as i am facing the same eroor in my application it will be helpful if you give me step up step resolution to fix it. It will be very helpfull to me
 
Hi, I am getting the exception on save as. The file is not getting saved in the specified location can any1 please help...
 
Does the application have permissions to write to the folder on the server?

I think that maybe the problem. Writing files to the server is not something that is normally allowed.

On your local machine are you using "http://localhost"? because this behaves differently to remote access and has more trust.
Which would explain why it works locally. If you are, try accessing it remotely on your XP machine and see if this will reproduce the error.
 
Last edited:
I am having exactly the same problem (Server 2008, Office Excel 2003, ASP.NET C#). Did you find a solution to this please. Thanks.
 
Hi,

I tried the fix given in the above link also. Even I get the same error "Exception from HRESULT: 0x800A03EC" on executing the line ObjExcel.ThisWorkbook.Save();.

If anyone know the solution, pls help me out to solve.

Thanks
Priya
 
I get the same error trying to write to XLS files from a different language/program.

The problem could be a simple one -
XLS files only support 256 columns of data, even though they support 60k+ rows.
ref: http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx

I fixed it two ways: change my data matrix such that it had fewer than 256 columns of data,
or
write to XLSX file. The new XLSX file format supports many more columns of data.

maybe this helps. maybe not.
 
I was getting the same exact error and none of the solutions here were relevant to my problem.

After poking around for a while, I found that the partition I was trying to write to was maxed out. I moved a bunch of un-needed files to an archive to clear up some room and the problem was resolved.
 
Back
Top