1

Unable to create the excel file at particular path when the application is run from IIS. But its created when the code is debuged using visual studio 2008.Even i have tried out using absolute path and using server.mappath() function but in vain.Server throws the error : HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Error.aspx

The code is given below:

private void CreateExcel(DataTable dt)
    {
        try
        {

        FilePath =  "\\\\192.168.1.252\\GNC Reports\\TallyExport.xls";
            Excel.Application oXL = new Excel.Application();

            //Get a new workbook.
            Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Type.Missing));

            // *************** Sheet 1
            Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Sheets["Sheet1"];
            oSheet.Name = "Journal";
            WriteWxcel(oSheet, dt, 3);

            //***************** Sheet 2
            oSheet = (Excel._Worksheet)oWB.Sheets["Sheet2"];
            oSheet.Name = "Payroll";
            WriteWxcel(oSheet, dt, 4);

            // ************* Sheet 3
            oSheet = (Excel._Worksheet)oWB.Sheets["Sheet3"];
            oSheet.Name = "Receipt";
            WriteWxcel(oSheet, dt, 2);

            //Save Excel File
            oWB.SaveAs(FilePath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            oXL.Quit();

        }
        catch (Exception ex)
        {
            BussinessLayer.CMSException.Instance.HandleMe(this, ex);
        }

    }
1
  • yes.. i am getting the following exception: ::1 - 1/12/2012 3:59:53 PM ASP.tally_tallyusercontrol_tallyexport_ascx - Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005. - at Tally_TallyUserControl_TallyExport.CreateExcel(DataTable dt) in c:\inetpub\wwwroot\GNC\Tally\TallyUserControl\TallyExport.ascx.cs:line 523 Commented Jan 12, 2012 at 10:40

1 Answer 1

7

Using Office Interop from server-like scenarios (IIS/ASP.NET/Windows Service...) is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Another point is that since windows vista there have been several security-related changed which prevent doing any "desktop-like" things (for example printing, writing to a network share...) from a Windows Service...

Alternative to Interop:

There are many options to read/edit/create Excel files without Interop:

MS provides the free OpenXML SDK V 2.0 - see http://msdn.microsoft.com/en-us/library/bb448854%28office.14%29.aspx (XLSX only)

This can read+write MS Office files (including Excel).

Another free option see http://www.codeproject.com/KB/office/OpenXML.aspx (XLSX only)

IF you need more like handling older Excel versions (like XLS, not only XLSX), rendering, creating PDFs, formulas etc. then there are different free and commercial libraries like ClosedXML (free, XLSX only), EPPlus (free, XLSX only), Aspose.Cells, SpreadsheetGear, LibXL and Flexcel etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.