Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code here I am merging Files from a source Folder into a Destination Folder...

Its working Correctly in local machine but when i hosted it in IIS server Merging is not Happening

I have given full control for the corresponding folders in IIS

Please give me some valuable suggetions to fix this problem?




private void Merge(string strSourceFolder, string strDestinationFile)
        {
            try
            {
                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                ExcelApp.Visible = false;
               
                Microsoft.Office.Interop.Excel.Application appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
               
                //Create destination object
                Microsoft.Office.Interop.Excel.Workbook objBookDest = ExcelApp.Workbooks.Add(missing);
                objBookDest.UserControl = true;
               
                foreach (string filename in Directory.GetFiles(strSourceFolder))
                {
                    //string filename1;
                    
                    if (File.Exists(filename))
                    {                    
                      
                        Microsoft.Office.Interop.Excel.Workbook objBookSource = ExcelApp.Workbooks._Open
                        (filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
                        ,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


                        //Browse through all files.
                        foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in objBookSource.Worksheets)
                        {

                            string Sheetname = sheet.Name.ToLower();
                            //sheet.Name = Sheetname.Substring(1);

                            sheet.Copy(Type.Missing, objBookDest.Worksheets[objBookSource.Worksheets.Count]);
                            objBookSource.Close(Type.Missing, Type.Missing, Type.Missing);
                            objBookSource = null;
                        }

                    }

                }

                foreach (string filename1 in Directory.GetFiles(Server.MapPath("~\\MergeReports\\")))
                {
                    if (File.Exists(filename1))
                    {
                        File.Delete(strDestinationFile);
                        break;
                    }
                }

             


                objBookDest.SaveAs(strDestinationFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, myExcel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                 objBookDest.Close(Type.Missing, Type.Missing, Type.Missing);


                objBookDest = null;
                ExcelApp = null;

                string[] filePaths = Directory.GetFiles(Server.MapPath("~\\Merge\\"));
                foreach (string filePath in filePaths)
                    File.Delete(filePath);
            }
            catch (System.Exception e)
            {
                objException = new BaseException(BasePage.GetCurrentUser.UserID.ToString(), e);
            }
        }
Posted
Updated 13-Apr-12 3:04am
v2
Comments
ZurdoDev 13-Apr-12 9:04am    
What's the error?
Tony Tom.k 13-Apr-12 9:15am    
In IIS its showing the error in This line(4th line) itself

Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp
not able to generate

I read in some forums that Interop.Excel is not supported in IIS
may i know that information is correct or not Is there any alternative ways to fix this problem..

Locally it wont make any problem but my application needs to be hosted in IIS
Tony Tom.k 16-Apr-12 8:48am    
Its showing this error Exacltly

2012-04-16 14:38:55,635 [3] ERROR Exception
Application Id:Exception{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.}
2012-04-16 14:38:55,878 [3] ERROR Exception Trace
at Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)

at AMC_Main.Reports.GetperformanceReport.Merge(String strSourceFolder, String strDestinationFile)

My Root folder have 2Gb space now
Tony Tom.k 24-Apr-12 5:53am    
By Error Tracking its giving this error Is there any solutions to fix this error
I have given Permissions in componenet Services Registery and etc for IIS Users

2012-04-24 14:38:50,536 [6] ERROR Exception Application Id:Exception{Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.}

The Interop is an interface to the excel.exe. The local system can access C:/program files but the IIS has its own directory structure. I think you can configure the IIS to include C:/program files in its directory structure. I just don't know how.
 
Share this answer
 
Comments
Tony Tom.k 16-Apr-12 9:13am    
I have given full control permission for Microsoft Excel Applications in DCOM Config (AdministrativeTools>Component Services>Computers>MyComputer>Dcom Config>msexcelapp)
problem still there
Tony Tom.k 24-Apr-12 5:54am    
By Error Tracking its giving this error Is there any solutions to fix this error
I have given Permissions in componenet Services Registery and etc for IIS Users

2012-04-24 14:38:50,536 [6] ERROR Exception Application Id:Exception{Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.}
First of all you have to give Permission for Your Excel Application.....
in Dcom Config.....


http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/b6388275-b295-4e55-8c25-6d8788eac1ca/[^]


Here They have Explained Every thing about Permissions...



In IIS Default Application pool You Have to set Identity into network Service

and In Advanced properties we have to enable 32 bit application into true if its false....
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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