Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have developed an ASP.Net project in which I want to produce some excel reports.

When I run this program on my local system, there is no problem in viewing those excel files, but after putting that software on server (Windows Server 2003 r2) I can not view the reports and I get the following error:

Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.

my code is here:

C#
Microsoft.Office.Interop.Excel.Application oXL;
        Microsoft.Office.Interop.Excel.Workbook oWB;
        Microsoft.Office.Interop.Excel.Worksheet oSheet;
        Microsoft.Office.Interop.Excel.Range oRange;
oXL = new Microsoft.Office.Interop.Excel.Application();
        
        //oXL.Visible = false;

        //Get a new workbook
        oWB = (Microsoft.Office.Interop.Excel.Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));
        oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.ActiveSheet;

        #endregion

        #region Styles

        Microsoft.Office.Interop.Excel.Style style_Header = null;//Reports_Header_Style_Func(oWB);
        Microsoft.Office.Interop.Excel.Style style_Titles = null; //Reports_Columns_Title_Style_Func(oWB);

        #endregion

        #region Columns_Titles

        string[,] _Titles = new string[1, 10];

        _Titles[0, 0] = "Product";
        _Titles[0, 1] = "Product(U)";
        _Titles[0, 2] = "Manufact";
        _Titles[0, 3] = "Price(U)";
        _Titles[0, 4] = "Daily Usd";
        _Titles[0, 5] = "Daily Rec";
        _Titles[0, 6] = "Daily Ret";
        _Titles[0, 7] = "Stock";

        #endregion

        #region Report_Building

        #region Header

        oRange = oSheet.get_Range("A1", "H1");
        oRange.Cells[1, 1] = "Materials Used In Well: " + _wellName + " In Date: " + _fDate.ToString();
        oRange.Merge(System.Reflection.Missing.Value);
        oRange.Style = style_Header;

        #endregion

        #region Titles

        oRange = oSheet.get_Range("A2", "H2");
        oRange.Value2 = _Titles;
        oRange.Style = style_Titles;

        #endregion

        int i = 3;
        foreach (var item in Bll_obj_Material.Get_Materials_By_WellObjCodeandfDate(_wellObjCode, _fDate))
        {
            oSheet.Cells[i, 1] = item.Product.Product1;
            oSheet.Cells[i, 2] = item.ProductUnit.ProductUnit1;
            oSheet.Cells[i, 3] = item.ProductManufacture;
            oSheet.Cells[i, 4] = item.PriceUnit.PriceUnit1;
            oSheet.Cells[i, 5] = item.DailyUsed;
            oSheet.Cells[i, 6] = item.DailyRec;
            oSheet.Cells[i, 7] = item.DailyReturn;
            oSheet.Cells[i, 8] = (item.StartAmount + item.DailyRec) - (item.DailyReturn + item.DailyUsed);
            i++;
        }

        oSheet.Columns.AutoFit();

        int max_row = i - 1;
        string max_index = "H" + max_row.ToString();

        oRange = oSheet.get_Range("A1", max_index);
        oRange.Borders.Weight = 2;

        oRange = oSheet.get_Range("A2", max_index);
        oRange.Font.Size = 8;

        oRange = oSheet.get_Range("A1", "H1");
        oRange.Font.Size = 9;

        #endregion

        #region Save_and_Open_Report

        string _fileName = "Material_Report_of_" + _wellName + "(" + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ")" + ".xls";

        string _savePath = Server.MapPath("~") + "\\ExcelReports\\" + _fileName;

        oWB.SaveCopyAs(_savePath);

        string _openPath = Request.ApplicationPath;

        _openPath = _openPath + "/ExcelReports/" + _fileName;

        HyperLink_TEMP.NavigateUrl = _openPath;

        HyperLink_TEMP.Visible = true;

        HyperLink_TEMP.Text = "Download Generated Report";

        
        #endregion


Thanks a lot in advance!
Posted
Updated 17-Apr-11 21:32pm
v4
Comments
Dalek Dave 18-Apr-11 3:32am    
Edited for Grammar and Readability.

Here you go for the solved solution

Problem in Microsoft.Office.Interop.Excel[^]

Update
----------------------------

It's a permission error....apply the below steps(Copied from above link), that's all

Step 1 : Go to run type dcomcnfg

Step 2 : Click >Component services >Computes >My Computer>Dcom config> and select micro soft Excel Application>

Step 3 : Right Click on Microsoft Excel Application>Properties>Give Asp.net Permissions

Step 4 : Select Identity table >Select interactive user >select ok
 
Share this answer
 
v3
Comments
alijoongolgoli 18-Apr-11 1:55am    
Thanks a lot for your answers.
But I had tried both solutions that you have mentioned before, but I still have the same problem!
Any other suggestions? Do I make a mistake in my Code? Should I use Excel Application, workbook and worksheet as I have used in my code? Do I need to change a reference or something like that?
I would be glad if you help me! Thanks!
thatraja 18-Apr-11 10:30am    
Check my updated answer
Dalek Dave 18-Apr-11 3:33am    
Spot on. I would have said the same.
Jeffrey Enzo 18-Apr-11 10:43am    
Good solution! 5 for you!
If you have checked that the server has enough memory and disk space, then the best guess is that it is a permissions issue. There is a discussion of this problem with various solutions you can try here[^]
 
Share this answer
 
Comments
alijoongolgoli 18-Apr-11 1:56am    
Thanks a lot for your answers.
But I had tried both solutions that you have mentioned before, but I still have the same problem!
Any other suggestions? Do I make a mistake in my Code? Should I use Excel Application, workbook and worksheet as I have used in my code? Do I need to change a reference or something like that?
I would be glad if you help me! Thanks!
Microst doesn't reccommend to use Interop.Excel for server programming.

Use OpenXML instead.

[edit]DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously. - OriginalGriff[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900