简体   繁体   English

Microsoft Excel无法访问ASP.net Project中的文件

[英]Microsoft Excel cannot access the file in ASP.net Project

I created web application that read excel file per row, and when i run it from my localhost it work perfectly. 我创建了一个Web应用程序,该应用程序每行读取excel文件,当我从本地主机运行它时,它可以正常运行。 But when i deploy it to web server [win 7 64 bit], it generate error like this : 但是,当我将其部署到Web服务器[win 7 64位]时,它会生成如下错误:

Microsoft Excel cannot access the file 'C:\TestReadExcel\testdata.xlsx'. 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.

This error came from this code (i used Microsoft.Office.Interop.Excel): 此错误来自以下代码(我使用了Microsoft.Office.Interop.Excel):

Line 195:        Dim workbook = xlApplication.Workbooks.Open(fileName)
..
..

I already tried various way : 我已经尝试过各种方法:

 1. add folder **desktop** C:\Windows\System32\config\systemprofile\ and in C:\Windows\SysWOW64\config\systemprofile  -it not working
 2. add security account for network services and iis_iusrs in DCOM config - microsoft excel application (allow all) - it not working
 3. already restart my web server after i configured step 1-2 , and still not working
 4. already test to add security account full control in folder C:\TestReadExcel\ , and still not working

Is there anything else that i need to do to solve this issue? 我还有什么需要解决的问题吗? or is there any way than use interop excel ? 还是有什么方法比使用interop excel还好?

Need your help thank you. 需要您的帮助谢谢。

use Server.Mappath to get the file path. 使用Server.Mappath获取文件路径。 and make sure IIS_User have read rights to that folder where you have placed your Excel File. 并确保IIS_User对您放置Excel文件的文件夹具有读取权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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