Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
should i set any permission from code behind
please someone help...
picupload.SaveAs(server_path);
while i am trying to upload/save the image/file
this error is thrown
 
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 14-Jan-13 20:47pm
Edited 17-Jan-13 21:16pm
v9
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Miss Maheshwari at 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 at 15-Jan-13 4:51am
   
Could you show some more of your code?
Miss Maheshwari at 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 at 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);
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Comments
Miss Maheshwari at 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 at 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 at 16-Jan-13 2:54am
   
i have already set the permission to write a folder
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

HttpPostedFile PostedFile = Request.Files[i];
           if (PostedFile.ContentLength > 0)
           {
               string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
               PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
           }
  Permalink  
Comments
Miss Maheshwari at 15-Jan-13 5:07am
   
what should i use in i
it throws error Use of unassigned local variable 'i'
kanjolia gopal at 15-Jan-13 5:13am
   
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(FileUpload.FileName);
PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
}
kanjolia gopal at 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 at 15-Jan-13 5:18am
   
yeah i have already done that but it throws the same error
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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

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

  Print Answers RSS
0 Maciej Los 589
1 OriginalGriff 419
2 CPallini 205
3 RyanDev 175
4 Sergey Alexandrovich Kryukov 170
0 OriginalGriff 5,649
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,689
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid