Results 1 to 2 of 2

Thread: Check if directory exists

Threaded View

  1. #1

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

    Check if directory exists

    I am allowing people to upload files to my server. For each new user I want to create a different directory to stored their upload files. The problem is everytime the user uploads a file it is creating a new directory...So if I upload 3 files, it creates 3 directories and stores 1 file in each.

    what I want it to do is...If the user uploads a file, then create a directory to stored their files in...for each file uploaded store all the uploads for that user, in that (newly created) directory.

    here is my code...I just need some help with the logic of determining if the users directory already exists.
    VB Code:
    1. Dim Filename As String = ""
    2.  
    3. [COLOR=red]This is where I think the problem is but how do I correct it[/COLOR]
    4. 'Declare the creation of a new directory
    5. Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\\") & Guid.NewGuid.ToString)
    6. Dim FilePath As String = ""
    7.  
    8. FilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "\EmailAttachments\\" & newDir.Name & "\\"
    9.  
    10. 'Check to see if the directory exists
    11. If (Directory.Exists(newDir.ToString) = False) Then
    12.       'If the Directory doesn't exist, create it.
    13.       newDir.Create()
    14. End If
    15.  
    16. 'Get the filename of the attachment (uploaded file)
    17. Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)
    18.  
    19. 'Save the uploaded file to the specified FilePath
    20. 'with the specified Filename
    21. attachmentFile.PostedFile.SaveAs(FilePath & Filename)
    22.  
    23. 'Add the uploaded files name to the listbox
    24. lstAttachments.Items.Add(Filename)
    Last edited by Memnoch1207; Dec 4th, 2003 at 12:33 PM.
    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