错误:System.IO.FileNotFoundException:找不到文件

时间:2013-11-07 09:23:21

标签: filenotfoundexception syncfusion

我在Syncfusion excel文件下载的错误日志中收到此错误。它每天发生几次,但我自己从来没有得到过这个错误。该文件确实存在于服务器上,并且大部分时间都可以正常工作,这使我很难调试。该网站位于IIS上的.Net 4中,并且从GAC引用了syncfusion dll。 Syncfusion版本是8.303.0.21。任何关于潜在原因的想法都将受到赞赏。

代码。

Private XlsIO As ExcelEngine
Private XlsWorkbook As IWorkbook
Dim str As String = Server.MapPath("Downloads/ExcelSpeedGen/excelfile.xls")
XlsIO = New ExcelEngine
XlsWorkbook = XlsIO.Excel.Workbooks.Open(str)
XlsRSheet = XlsWorkbook.Worksheets("raw data")
XlsRSheet.ImportDataTable(datatable, False, 2, 1, True)
XlsWorkbook.SaveAs("Excel.xls", ExcelSaveType.SaveAsXLS, Response, Syncfusion.XlsIO.ExcelDownloadType.PromptDialog)
XlsWorkbook.Close()

错误。

  System.Web.HttpException (0x80004005): Exception of type 'System.Web.HttpException' was 
  thrown. --->             System.Web.HttpUnhandledException (0x80004005): Exception of type 
  'System.Web.HttpUnhandledException' was thrown. ---> System.IO.FileNotFoundException: File   
  D:\inetpub\Secure\mywebsite\Downloads\ExcelSpeedGen\excelfile.xls could not be found. Please
  verify the file path. at Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open
  (String fileName, ExcelOpenType openType, ExcelVersion version, ExcelParseOptions options) at 
  Syncfusion.XlsIO.Implementation.Collections.WorkbooksCollection.Open(String filename) at 
  Default.form1_Load(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) 
  at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at 
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
  includeStagesAfterAsyncPoint) at System.Web.UI.Page.HandleError(Exception e) at 
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean 
  includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, 
  Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at 
  System.Web.Util.AspCompatApplicationStep.System.Web.HttpApplication.IExecutionStep.Execute() at 
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) at 
  System.Web.HttpAsyncResult.End() at ASP.ideasplusbaseline_aspx.EndProcessRequest(IAsyncResult ar) at 
  System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)

1 个答案:

答案 0 :(得分:0)

您是否可以尝试在Stream中打开文件(excelfile.xls)并将流传递给XlsIO,如果仍然在XlsIO中再现相同的问题然后共享示例,则最好对此异常的确切原因进行排序。共享代码段供您参考。

Dim str As String = Server.MapPath("Downloads/ExcelSpeedGen/excelfile.xls")
Dim fileAsStream As FileStream = New FileStream(str, FileMode.Open, FileAccess.Read, FileShare.Read)
XlsIO = New ExcelEngine
XlsWorkbook = XlsIO.Excel.Workbooks.Open(fileAsStream)

谢谢, Sathish所在

相关问题