Click here to Skip to main content
15,891,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
should i set any permission from code behind
please someone help...
C#
picupload.SaveAs(server_path);

while i am trying to upload/save the image/file
this error is thrown

XML
Access to the path 'D:\INETPUB\VHOSTS\softmarvel.com\site1\Member_Pic\12.png' is denied.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\INETPUB\VHOSTS\softmarvel.com\site1\Member_Pic\12.png' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Posted
Updated 17-Jan-13 21:16pm
v9

Read the Last paragraph of your error Message.
The error is due to the access rights, You are not authorized to use that resource or Image(in this case).
More Information about this exception: UnauthorizedAccessException[^]
 
Share this answer
 
Comments
Miss Maheshwari 15-Jan-13 4:42am    
i can do that on my system/computer but when i upload the project then it throws this error
Shanu2rick 15-Jan-13 4:51am    
Could you show some more of your code?
Miss Maheshwari 15-Jan-13 5:14am    
if (picupload.PostedFile != null && picupload.PostedFile.ContentLength > 0)
{


string cat_pic = picupload.PostedFile.FileName;
string ex_pic = System.IO.Path.GetExtension(cat_pic).ToLower();
string picname = Convert.ToString(mid) + ex_pic;
string dir_path = "Member_Pic";
string save_path = "Member_Pic\\" + picname;
string db_path = "~\\Member_Pic\\" + picname;
server_path = Server.MapPath(save_path);


picupload.SaveAs(server_path);
Shanu2rick 15-Jan-13 5:39am    
Try Something like this

if (picupload.PostedFile != null && picupload.PostedFile.ContentLength > 0)
{
string cat_pic = picupload.PostedFile.FileName;
string ex_pic = System.IO.Path.GetExtension(cat_pic).ToLower();
string picname = Convert.ToString(mid) + ex_pic;
string dir_path = "Member_Pic";
string save_path = "Member_Pic\\" + picname;
string db_path = "~\\Member_Pic\\" + picname;
server_path = Server.MapPath(@"~\Menmber_Pic\")+picname; //CHANGES

picupload.SaveAs(server_path);
}
Hi,

This error is because of Access to that particular folder.

This will help you : http://technet.microsoft.com/en-us/library/cc730708(WS.10).aspx[^]
 
Share this answer
 
C#
if (FileUpload1.HasFile)
           {

               FileUpload1.PostedFile.SaveAs("Your  Location Path");
           }



You Can used It And It Works



If Your Problem Exist Please Give me Your Comment
 
Share this answer
 
Comments
Miss Maheshwari 15-Jan-13 5:47am    
yes its workin fine on local system but on remote server it throws the same error
rizwan muhammed khan gouri 15-Jan-13 6:46am    
System.UnauthorizedAccessException: Access to the path
for Exception you can Provide folder Access using permission setting on your Pennel like c-penel than it will use on to the server
Miss Maheshwari 16-Jan-13 2:54am    
i have already set the permission to write a folder
C#
HttpPostedFile PostedFile = Request.Files[i];
           if (PostedFile.ContentLength > 0)
           {
               string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
               PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
           }
 
Share this answer
 
Comments
Miss Maheshwari 15-Jan-13 5:07am    
what should i use in i
it throws error Use of unassigned local variable 'i'
[no name] 15-Jan-13 5:13am    
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(FileUpload.FileName);
PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
}
[no name] 15-Jan-13 5:14am    
if (FileUpload.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(FileUpload.FileName);
PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
}
Miss Maheshwari 15-Jan-13 5:18am    
yeah i have already done that but it throws the same error
I am assuming that you have hosted your website on a shared server. If that is the case, the folder(Member_Pic) has to be given read/write permission as the error clearly says that. Generally, you can do that by using the control panel given to you by your service provider. Also, try contacting customer services, they might do it for you.
 
Share this answer
 
Hi ! there would be only two reason for this:

1- First which is told by Zafar Sultan   Give read/write permission to your image folder.
2- Our this path is not exist on your server D:\INETPUB\VHOSTS\softmarvel.com\site1\Member_Pic\12.png'

Please check that, I hope this will solve your issue. 
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900