1

i am trying to upload files in asp.net and putting a specific path to be saved. windows user.

it is outputting me an error :

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path 'C:\Users\USER\Desktop\fyp2\CMS TEST4\CMS\CMS\Upload' is denied. 

my code is:

 var guid = Guid.NewGuid();
 if (File.HasFile)
 {
   var length = File.PostedFile.FileName.ToString().Length;
   var ind = File.PostedFile.FileName.ToString().IndexOf('.');
   var sdfs=guid.ToString()+File.PostedFile.FileName.ToString().Substring(ind, length - ind);
   File.PostedFile.SaveAs("C:\\Users\\USER\\Desktop\\fyp2\\CMS TEST4\\CMS\\CMS\\Upload");

 }
1
  • 1
    That means the account running the web server doesn't have access to the folder. Commented Sep 14, 2011 at 19:40

4 Answers 4

3

The ASP.NET worker process does not have access rights to that path. By default I believe IIS worker processes run under the Network service account. You can either add write rights for the folder to this account, or set up a new Application Pool with a different identity (i.e. a user that does have write rights).

Sign up to request clarification or add additional context in comments.

Comments

3

As simple as the error puts it, your application requires the folder to have proper write permissions.

I'm asuming this is a Web Application. In that case, you'll need that the user which IIS uses to run applications has Write permissions over the specified folder.

Comments

3

The users directory is fairly locked down. If the account the web server is running under is not the specified user, it will not, by default, have access to the path. You can either grant explicit access to that path to the account running your web server, or create a folder with appropriate permissions external to that path and create a link on the user's desktop.

Comments

1

Looks like current user has not permission to save. Before writing try use FileSystemRights with AccessControlType.Allow to know permission info of the destination.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.