1

In my C#.net application, I am creating excel file and it is working fine at my local system but its give below error when deployed the application in IIS

  • My Web server don't have office installed.

Error:

ExceptionMessage> Microsoft Excel cannot access the file '\............xltm'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. System.Runtime.InteropServices.COMException

umesh.chape
  • 2,895
  • 5
  • 16
  • 17
  • you mention workbooks.open in the title, how is that involved here? – Marcucciboy2 Feb 26 '20 at 13:48
  • This is line: WB = xApp.Workbooks.Open(oTemplate.ToString(), missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); – umesh.chape Feb 26 '20 at 13:50
  • 1
    **DON'T** use Office interop on a web server. For starters, you'd need to buy a separate license for *every* user. Second, if you're careless you'd end up opening a new Excel instance for each request, quickly exhausting all RAM. Even if you're carefull, you're creating a new instance for each concurrent request which wastes a *lot* of RAM. And you'd still have to pay for all of them – Panagiotis Kanavos Feb 26 '20 at 13:51
  • 1
    Web applications use libraries like Epplus to generate real `xlsx` files instead without using Excel. `xlsx` is a zip package containing XML files in a well-defined format, which means you could just creates the files on the fly. Epplus though makes this a *lot* easier, as easy as eg `sheet.Cells.LoadFromCollection()` – Panagiotis Kanavos Feb 26 '20 at 13:53

0 Answers0