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

vipin_pc

New member
Joined
Nov 26, 2008
Messages
4
Hi All,

In one the intranet sites which I have developed, im 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:
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

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.
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

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"
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

The exact error im getting is
System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

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.
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

I checked the user accounts and also permissions. Its NETWORK SERVICES and I have given full permission. Im 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"

Im sorry that in my thread i have not mentioned that the Windows 2008 Server is trial version.
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

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
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

Hi, I am getting the exception on save as. The file is not getting saved in the specified location can any1 please help...
 
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

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 by a moderator:
Re: Error Exception from HRESULT: 0x800A03EC when saving an excel file in C#-ASP.NE

I am having exactly the same problem (Server 2008, Office Excel 2003, ASP.NET C#). Did you find a solution to this please. Thanks.
 
Back
Top