Saving an uploaded file with HttpPostedFileBase.SaveAs in a physical path

后端 未结 2 793
温柔的废话
温柔的废话 2021-01-01 18:10

I\'d like to save an uploaded file to a physical path by the method HttpPostedFileBase.SaveAs().

When I choose a physical path, an exception appears ind

2条回答
  •  时光说笑
    2021-01-01 18:43

    The Server.MapPath works only with physical locations that are part of the website. If you want to save the file outside you could use the following:

    var fileName = Path.GetFileName(fileurl.FileName);
    fileurl.SaveAs(Path.Combine(@"c:\projects", fileName));
    

    Make sure though that the account under which your application pool is executing is granted write permissions to this folder.

提交回复
热议问题