rxraza
asked on
UnauthorizedAccessException while uploading a file.
Hi folks:
I am getting the following exception while uploading a file using HtmlInputFile.
System.UnauthorizedAccessE xception: 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.Sa veAs(this. txtLogo.Va lue);
where txtLogo has been declared as:
protected System.Web.UI.HtmlControls .HtmlInput File 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.
I am getting the following exception while uploading a file using HtmlInputFile.
System.UnauthorizedAccessE
I am using the following code to upload a file in the button click event.
this.txtLogo.PostedFile.Sa
where txtLogo has been declared as:
protected System.Web.UI.HtmlControls
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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.
ASKER
Even I gave full control including modify to that account but no use.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
It worked with IUSR_MACHINE having write permissions to the destination folder and <identity impersonate="true" /> in web.config file.
have you give modify access to the asp.net user ?
Regards!
B..M