WebClient

P

piyush mahajan

Hi
I am using webclient downloadfile method to download a file from server Like

using system.net;
WebClient web = new WebClient();
web.DownloadFile("webaddress/filename.txt", "E:\\");

for a while it works fine but now it gives error as
System.UnauthorizedAccessException: Access to the path 'E:\' is denied.
Help me
Thanks


Submitted via EggHeadCafe - Software Developer Portal of Choice
Build a Selected Text Favorites Utility for your Web Site
http://www.eggheadcafe.com/tutorial...c-86feb39cae83/build-a-selected-text-fav.aspx
 
M

Mr. Arnold

piyush said:
Hi
I am using webclient downloadfile method to download a file from server Like

using system.net;
WebClient web = new WebClient();
web.DownloadFile("webaddress/filename.txt", "E:\\");

for a while it works fine but now it gives error as
System.UnauthorizedAccessException: Access to the path 'E:\' is denied.
Help me


You need to find out what account credentials the application is running
under when access is denied. The access denied means the account
credentials the application is running under at the time of access to
what E: is mapped to doesn't have the permission to access E:.


You have an account permissions issue that the application is using to
access E:.
 
S

sloan

To follow up, here is some code to return the user under which the code is
running.

Most likely , "ASPNET", and that account needs rights granted to it to write
files out.



private string FindIIdentity()
{

try
{

string returnValue = string.Empty;

WindowsIdentity ident = WindowsIdentity.GetCurrent();
returnValue = ident.Name;

try
{
returnValue += " on " + System.Environment.MachineName;
}
catch (Exception ex)
{
Conditionals.Trace.WriteMessage(ex.Message);
}

return returnValue;
}


catch (Exception ex)
{
Conditionals.Trace.WriteMessage(ex.Message);
return "Error Finding Identity";
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top