当前位置: 动力学知识库 > 问答 > 编程问答 >

In ASP.net I am getting error Access to the path '~\Upload\1_myimage.png' is denied?

问题描述:

I have uploaded my website on server when i try to save image on uploaded folder called Upload then it gives error

Line 114: {

Line 115: string str = imagepath;

Line 116: fuStudentPhoto.PostedFile.SaveAs(Server.MapPath("~/Upload/" +str));

Line 117: Image = str;

I gave all permission rights to Upload folder but still its stuck here. Help me anyone to solve this issue...

网友答案:

Give full permissions for user IIS_IUSRS for your 'Upload' directory on server.

网友答案:

in your action [HttpPost] your input will be HttpPostedFileBase file and you input type file should have name="file" then:

<input type="file" name="file" id="file" />

in your .net controller

var filename = Sytem.IO.Path.GetFileName(file.FileName);

file.SaveAs(Server.MapPath(Path.Combine("~/Upload/", filename)));

do not forgot to put enctype="multipart/form-data" in your form

网友答案:

Line 114: { Line 115: string str = imagepath; Line 116: fuStudentPhoto.PostedFile.SaveAs(Server.MapPath("~/Upload/" +str)); Line 117: Image = str;

The above will not work and you will have to replace it with

filename = Path.GetFileName(file_upload.PostedFile.FileName);
file_upload.PostedFile.SaveAs(Server.MapPath(SaveLocation + "\\" + filename));

Do remember to specify the filename too in the SaveAs method.

Credit: ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server

分享给朋友:
您可能感兴趣的文章:
随机阅读: