PDA

Click to See Complete Forum and Search --> : Saving uploaded file error


Memnoch1207
Dec 3rd, 2003, 04:21 PM
I am receiving this error

Could not find a part of the path
"c:\inetpub\wwwroot\www01\ESPEmail\df268d2c-5666-4171-a4a1-ca703ff3bce7\Test.doc".


I am trying to save an uploaded file to a dynamically created directory, but I keep getting the error above

Here is my code

Dim Filename As String = ""

'Declare a new directory to be created
Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\") & Guid.NewGuid.ToString)

'Grab the name of the file
Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)

'Create the new directory
newDir.Create()

'Save the uploaded file to the new directory
attachmentFile.PostedFile.SaveAs(Server.MapPath(newDir.Name) & "\" & Filename)

'Add the filename to the listbox
lstAttachments.Items.Add(Filename)


It creates the new (GUID) directory just fine, it just doesn't save the file to it.
any ideas on how to fix this???

Memnoch1207
Dec 3rd, 2003, 04:51 PM
'I have also tried it with this line of code
'but I get the same error
attachmentFile.PostedFile.SaveAs(Server.MapPath(newDir.Name & "\") & Filename)

hellswraith
Dec 3rd, 2003, 05:15 PM
Don't know much about the upload, but does ASP.NET have permission to write that file to disk in that directory?

Memnoch1207
Dec 3rd, 2003, 09:11 PM
My assumption would be yes...Since it is actually creating the directory I would think that it would have permission to write the file into that directory as well.

Memnoch1207
Dec 4th, 2003, 11:39 AM
actually, I got it to work like this

Dim Filename As String = ""
Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\\") & Guid.NewGuid.ToString)
Dim FilePath As String = ""

FilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "\EmailAttachments\\" & newDir.Name & "\\"

If (Directory.Exists(newDir.ToString) = False) Then
Response.Write(newDir.ToString & " doesn't exist")
newDir.Create()
End If

Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)
attachmentFile.PostedFile.SaveAs(FilePath & Filename)