[英]Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx'
I have a MVC application that reads and uploads an Excel file and processes that file in the app, everything works fine on my local machine, but as soon as I deploy to the server,I get the following error above.我有一个 MVC 应用程序,它读取和上传一个 Excel 文件并在应用程序中处理该文件,在我的本地机器上一切正常,但是一旦我部署到服务器,我就会收到上面的以下错误。 I have added permissions to the IIS App Pool user to root folder, but as soon as I browse for a file through my app on my local machine, it fails with the above error.
我已将 IIS 应用程序池用户的权限添加到根文件夹,但是一旦我通过本地计算机上的应用程序浏览文件,它就会失败并出现上述错误。 If i test it on the deployed server it works fine.
如果我在部署的服务器上测试它,它工作正常。 Any idea what this is, I have seen a lot of posts on this, tried the suggestions but no luck.
知道这是什么,我看过很多关于此的帖子,尝试了建议但没有运气。 Any ideas, Please see my code below.
任何想法,请参阅下面我的代码。
try
{
if (file.ContentLength > 0)
{
var fileName = file.FileName;
var targetFolder = Server.MapPath("/");
string targetPath = Path.Combine(targetFolder, fileName);
file.SaveAs(targetPath);
you should use with tilde symbol(~) to point the root of the application你应该使用波浪号(~)来指向应用程序的根
Server.MapPath("~/");
and it's better to use subfolder like (make sure there is that folder)最好使用子文件夹(确保有那个文件夹)
Server.MapPath("~/uploads/")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.