简体   繁体   中英

Excel File is not downloaded in IIS Server

string path=Server.MapPath("../ExcelTemplate/DownloadExcelFiles/FacilitySetup" + ss + ".xls");
log.append("Mapped Path"+path, 100);
log.append("Start to SaveAs Worksheet", 100);
try
{
    ThisWorkBook.SaveAs("" + Server.MapPath("../ExcelTemplate/DownloadExcelFiles/FacilitySetup" + ss + ".xls") + "", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, missing, missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
    missing, missing, missing, missing, missing);


    //ThisWorkBook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, missing, missing, false, false,
    //    Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
}
catch (Exception exceptionObj)
{
    log.append("Exception During SaveAs" + exceptionObj.ToString(),100);
}
log.append("Worksheet SaveAs Successfully", 100);

Note:

  1. part of code sample is shown above
  2. I am Trying to download excel file
  3. File is downloaded in normal, but when i run same application on IIS Server excel file is not downloaded.
  4. i maintained log on each line
  5. i found during runing line ( saveAs()) normal execution is not going to next line
  6. ie problem occurs on saveAs()

How to solve it?

尝试不使用Server.MapPath,因为您已经有了物理路径

It sounds like you have a deadlock (and not an exception). As someone said in a comment, using Office interop in a server environment is a very bad idea. See: http://support.microsoft.com/kb/257757 for a lot of information as to why. Check out ClosedXML

I recently encountered a problem with downloading .xls files. Explanation is here: http://support.microsoft.com/kb/2123563 . Who knows, it might be a problem here as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM