Results 1 to 5 of 5

Thread: Saving uploaded file error

  1. #1

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861

    Saving uploaded file error

    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
    VB Code:
    1. Dim Filename As String = ""
    2.  
    3. 'Declare a new directory to be created
    4. Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\") & Guid.NewGuid.ToString)
    5.  
    6. 'Grab the name of the file
    7. Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)
    8.  
    9. 'Create the new directory
    10. newDir.Create()
    11.  
    12. 'Save the uploaded file to the new directory
    13. attachmentFile.PostedFile.SaveAs(Server.MapPath(newDir.Name) & "\" & Filename)
    14.  
    15. 'Add the filename to the listbox
    16. 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???
    Last edited by Memnoch1207; Dec 3rd, 2003 at 05:51 PM.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  2. #2

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    VB Code:
    1. 'I have also tried it with this line of code
    2. 'but I get the same error
    3. attachmentFile.PostedFile.SaveAs(Server.MapPath(newDir.Name & "\") & Filename)
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Don't know much about the upload, but does ASP.NET have permission to write that file to disk in that directory?

  4. #4

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    actually, I got it to work like this
    VB Code:
    1. Dim Filename As String = ""
    2. Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\\") & Guid.NewGuid.ToString)
    3. Dim FilePath As String = ""
    4.  
    5. FilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "\EmailAttachments\\" & newDir.Name & "\\"
    6.  
    7. If (Directory.Exists(newDir.ToString) = False) Then
    8.      Response.Write(newDir.ToString & " doesn't exist")
    9.      newDir.Create()
    10. End If
    11.  
    12. Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)
    13. attachmentFile.PostedFile.SaveAs(FilePath & Filename)
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width