Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload permission denied with permissions set

Status
Not open for further replies.

PoppapumpJ

Programmer
Dec 17, 2001
86
US
I apologize if this is answered somewhere else but I have been unable to find it. I am about at my wits end.

I am attempting to upload a file to a folder using the file upload control. Here is the code behind my submit button

Code:
Dim strFileType As String = FileUpload1.PostedFile.ContentType
Dim intFileSize As Integer = FileUpload1.PostedFile.ContentLength
Dim strpath As String

strpath = Server.MapPath("newpics")

FileUpload1.PostedFile.SaveAs(strpath)

The error it gives states:
System.UnauthorizedAccessException: Access to the path 'c:\inetpub\ is denied.

Under security, I have allowed full control access to the following users
EVERYONE
ASPNET
IUSR_(machinename)

I am using Visual Web Developer 2005 and running in debug mode.

Any suggestions are greatly appreciated.

Thank you.
 
If you are using Windows 2003, you'll have to set the permissions for the Network Service account


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I added NETWORK SERVICE to have full control on that folder and still no luck.

I also tried uploading to different folders, some even outside of the web direcotry and still got the same error.

It is weird because it lets me write profile info to my APP_DATA folder (using Access Provider) and it has the same security settings as my upload folder.

Is there any chance the mappath function could be locking the folder?

Could Norton Anti-Virus be locking the folder? (unfortunatley I am not allowed to disable NAV)

Am I overlooking something simple?

Thanks for any suggestions,




 
OK, I feel like a big Bone Head.

The problem here turned out to be that I was not suppling a file name.

I changed my code to look like this and it worked like I expected it too.

Code:
Dim strFileType As String = FileUpload1.PostedFile.ContentType
Dim intFileSize As Integer = FileUpload1.PostedFile.ContentLength
Dim strpath As String
Dim strFileName As String

strFileName = Right(FileUpload1.PostedFile.FileName, Len FileUpload1.PostedFile.FileName) -FileUpload1.PostedFile.FileName.LastIndexOf("\"))

strpath = Server.MapPath("newpics") & strFileName

FileUpload1.PostedFile.SaveAs(strpath)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top