0

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...

3 Answers3

0

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

luki
  • 72
  • 2
0

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

0

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

Community
  • 1
  • 1
Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55