Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted (edited)

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

           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.

Edited by PlausiblyDamp
  • Administrators
Posted

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

appcmd set config -section:asp -enableParentPaths:true

however this is introducing a potential security risk.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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"

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

  • 3 weeks later...
  • 3 weeks later...
Posted (edited)
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.

Edited by JohnsHandle
  • 3 months later...
Posted
I am having exactly the same problem (Server 2008, Office Excel 2003, ASP.NET C#). Did you find a solution to this please. Thanks.
  • 3 months later...
  • 1 year later...
Posted

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

  • 7 months later...
Posted

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.

  • 1 year later...
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...