Click here to Skip to main content
14,698,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone, I'm trying to upload a file to my website using a method I found on the net. When i upload files in debug mode, it works fine, but when I try to upload on my website, I get this error.

Access to the path 'D:\Hosting\11029316\html\gizmoblog\Content\Images\dpi.jpg' is denied.

This is the method I'm using to upload files.

public ActionResult UpdateLogo(HttpPostedFileBase SiteLogo)
   if (SiteLogo.ContentLength > 0)
       var fileName = Path.GetFileName(SiteLogo.FileName);
       var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName);

Is there a way I can upload the file using a FTP stream? Or even upload them using a URI to my website like Really need help guys..
Updated 4-Jun-13 15:42pm
NotPolitcallyCorrect 4-Jun-13 21:21pm
Have you tried just giving access permission to that directory?
Dezmen Ceo Sykes 4-Jun-13 22:13pm
Not really, im gonna try now
Dezmen Ceo Sykes 4-Jun-13 22:19pm
I feell ike a derp! It worked lol
Nice... Yes if you find the error access to the path is denied, the solution is please try to grant the permission to the folder and I believe it will fix your issue.

1 solution

Some times you have no permission to access a particular folder or file. So you can give permission dynamically to that particular folder like below
var dInfo = new DirectoryInfo(@"D:\Hosting\11029316\html\gizmoblog\Content\Images\");
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));

Hope this helps

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