简体   繁体   中英

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. 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. 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/")

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