Link to home
Start Free TrialLog in
Avatar of rxraza
rxraza

asked on

UnauthorizedAccessException while uploading a file.

Hi folks:

I am getting the following exception while uploading a file using HtmlInputFile.

System.UnauthorizedAccessException: Access to the path "C:\personal\site.gif" is denied.

I am using the following code to upload a file in the button click event.

this.txtLogo.PostedFile.SaveAs(this.txtLogo.Value);

where txtLogo has been declared as:

protected System.Web.UI.HtmlControls.HtmlInputFile txtLogo;

I guess it has to do something with secutiry persmission to write to some directory but I do not how do I go about doing it. May be I have to impersonate some user account but I am not sure. thanks in advance.
Avatar of mmarinov
mmarinov

Hi rxraza,

have you give modify access to the asp.net user ?

Regards!
B..M
SOLUTION
Avatar of AerosSaga
AerosSaga

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rxraza

ASKER

AreosSaga:

C:\personal is the directory from which I am uploading the file. It is the source why would I need to give write permissions to the source directory. Depending upon the user's choice it could be any directory on the local machine.
well if you want asp.net to be able to access it your going to have to give it permissions for this particular folder.
Avatar of rxraza

ASKER

ok I did that. My application is running under anonymous user account which is IUSR_MACHINE. I added this account which is the internet guest user account but stil it did not work. Do I have to restart IIS?
try adding the 'everyone' group with write permissions.
Avatar of rxraza

ASKER

Even I gave full control including modify to that account but no use.
Avatar of rxraza

ASKER

yep that worked this time - everyone group with write permission. I can't see the uploaded file in root folder of the application. Where does it suppose to upload the file?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rxraza

ASKER

John:

Oops. Indeed I had a wrong example. I thought may be I need to pass in the path to source to saveas method. I was highly mistaken and I had an assumption that it will automatically save the file under application root which is totally absurd and wrong. I screwed big time under pressure.

Will try your approach of impersonation. thanks a lot for your help.
Avatar of rxraza

ASKER

It worked with IUSR_MACHINE having write permissions to the destination folder and  <identity impersonate="true" /> in web.config file.