Click to See Complete Forum and Search --> : Uploading File Access Denied.


ambreesh
September 8th, 2005, 03:52 PM
I am trying to upload a file using the following program

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then

Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
' Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn

Dim savelocation = "C:\upload\Data"
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")

I am not one of those people who would post random code on the website and ask people to debug. I have tested this code and it works fine for webshares, once I insert an absolute path in the savelocation string, I get the following error message.

Error: Access to the path "C:\upload\Data" is denied.

where "C:\uploade\Data is my absolute path. I have given all possible access to the folder "Data" including anonymous + ASPNET access.

Does some know what may be going wrong?

ambreesh
September 12th, 2005, 02:36 AM
can anyone suggest something? any off the hook ideas?

PM_
September 12th, 2005, 03:47 AM
You have to add the filename
File1.PostedFile.SaveAs(SaveLocation & "\" & fn)

Pieter

ambreesh
September 18th, 2005, 02:35 AM
anyone ?

mandapo
September 22nd, 2005, 10:02 AM
I'm having a similar problem with a site that i'm working with. Have you found a resolution?

ambreesh
September 25th, 2005, 12:49 AM
Come on guys, need urgent help, some one must know this.

mandapo
September 25th, 2005, 11:30 AM
I believe my problem was caused because the host machine is running IIS 6.0 under the default configuration which runs the .net worker process using the NETWORK_SERVICES identity instead of the ASPNET identity. If this is the case, the NETWORK_SERVICES machine user account should be given write permissions to the directrory.

ambreesh
September 27th, 2005, 01:51 PM
I think the IIS always runs under the identiy ASP_NET, I am not too sure of the Network Services itentity.

How did u find that out? does it work now

mandapo
September 27th, 2005, 03:55 PM
Yes, it works now..

http://support.microsoft.com/default.aspx?scid=kb;en-us;323245

Read step 7 under "Create the Data directory".

I also found this information:

http://www.dotnet247.com/247reference/msgs/58/292399.aspx
http://www.atstake.com/research/reports/eval_ms_ibm/analysis/2.8.1.html#dotnet

ambreesh
September 29th, 2005, 11:09 PM
i think my problem was a little different, the asp net user did not have access rights to the folder,... dumb mistake.