Reputation: 837
I would love to ask ,what is wrong with th following code ,because i've been trying to create a folder on my local machine but it does not work according to my expectactions. It gives me a Error saying :
Access to the path 'C:\inetpub\wwwroot//PrintLabels/' is denied
Code:
Directory.CreateDirectory(appPath + "//PrintLabels/");
Upvotes: 2
Views: 2432
Reputation: 386
The specified path must be on same machine or can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name.
It must be
string path = @"\\172.16.136.35\\SharedFolder1\\";
The IP Address replaces the use of the computer name. You must not use them both.
string path = @"\\ipaddress\comp_name\shared_folder\new_folder";
Should be:
string path = @"\\ipaddress\shared_folder\new_folder";
Note that the IP Adress is the one of the computer where the shared folder is, not the one from which you send your request.
Upvotes: 1
Reputation: 100527
Most likely (assuming missning asp.net tag) your code is running in ASP.Net application. Depending on chosen security model account the code runs under is either browser user's or special "anonymous" account. Both of accounts likley will not have write/create folder permissions in "inetpub\wwwroot" folder.
If you really want to let this access - figure out what user code runs under (i.e. check Environment.UserName at the moment of exception) - if you are ok to give this user permissiosn - navigte local explorer to folder you want to create files/folders in and adjust permissions on "security" tab of folder properties.
In general writing files to semi-random locations (especially system controller ones like windows/program files/inetpub) is not a good idea. Make sure you understand security implications of your actions...
Note: make sure to construct paths correcly. Path.Combine
is better way to do so over string concateneation and using long list of random slash/backslash characters.
Upvotes: 0
Reputation: 96
I think that it is the problem of using AppPath. Thats the path WWWroot. It is for create websites. so you may don't have correct access permissions.
You can try some another path that you have correct access permissions.
Upvotes: 0
Reputation: 4412
If you are using Windows Vista or above, then first close Visual Studio, then right-click its icon and select run as administrator option. Then when you execute the code, it should stop giving access denied exception.
Upvotes: 1