|
-
Dec 4th, 2003, 12:28 PM
#1
Thread Starter
Frenzied Member
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:
Dim Filename As String = ""
[COLOR=red]This is where I think the problem is but how do I correct it[/COLOR]
'Declare the creation of a new directory
Dim newDir As New DirectoryInfo(Server.MapPath("EmailAttachments\\") & Guid.NewGuid.ToString)
Dim FilePath As String = ""
FilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "\EmailAttachments\\" & newDir.Name & "\\"
'Check to see if the directory exists
If (Directory.Exists(newDir.ToString) = False) Then
'If the Directory doesn't exist, create it.
newDir.Create()
End If
'Get the filename of the attachment (uploaded file)
Filename = Path.GetFileName(attachmentFile.PostedFile.FileName)
'Save the uploaded file to the specified FilePath
'with the specified Filename
attachmentFile.PostedFile.SaveAs(FilePath & Filename)
'Add the uploaded files name to the listbox
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
-
Dec 4th, 2003, 07:32 PM
#2
Hyperactive Member
If you have a way of identifying users maybe come up with a way of incorporating that info into the naming of the directory, somethin like UserDirectory_PlaceTheirUserIdHere, then check if their directory exists. You could also save the guid in a database table associated with each user, then check if that entry exists before creating a new one, otherwise create a new directory and save that name off somewhere associated with the user.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|