www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: create new folders on the fly?

  1. #1
    Join Date
    Dec 2002
    Posts
    359

    create new folders on the fly?

    HI!

    i have a form where there are 2 pages. the 1st is for form data, the 2nd for uploading attachments. For each time a new form is filled out, it gets assigned an EventID (so the info can be looked at later).

    I am able to upload files to a folder (UploadedFiles) no problem.

    What I need is to be able to create a new folder in UploadedFiles for each new EventID. That way I can associate the attachments to specific Events. I would like the new folders to be named with the EventID (so EventID =44, the folder containing the attachments for it is in \UploadedFiles\44).

    The way I have it now, no new folders are created, and all attachments are put into UploadedFiles. So now when I view the attachments (I have a table that displays them) all attachments for all events are listed.

    I pass the EventID in the URL in order to display the correct event.

    Here is the code that uploads:


    Is there a way to add a new folder named with the EventID if it doesn't already exist? if it does, can the attachment be put in it (if it's for the same EventID)?

    THANKS!!!!!!
    Last edited by sanjuT; 08-16-2004 at 10:35 AM.

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    FSO has a function named 'CreateFolder()'.
    Code:
    Dim fso
    fso = Server.CreateObject("Scripting.FileSystemObject")
    fso.CreateFolder(EventID)
    Regards,
    Andrew Buntine.

  3. #3
    Join Date
    Dec 2002
    Posts
    359
    Thanks, but how could I incorporate this into my code?

    I am not sure where to put this in, or how to reference it.

  4. #4
    Join Date
    Nov 2003
    Posts
    655
    Before you save to disk, look for the directory. If it's not there, create it. Save to the directory, as it'll now be there. (Of course, it doesn't hurt to watch out for and handle errors.)

  5. #5
    Join Date
    Dec 2002
    Posts
    359
    THANKS!

    again, i am a relative newbie, so i do not know how to even do this correctly, but i understand the logic of it.

    so i check if the directory exists. how? test if that directory equals true? i know it would be a loop, so if it doesn't exist, i plug in the fso code?

    does the line:

    fso.CreateFolder(EventID)

    automatically create the directory named after the EventID?

    THANKS!!!

    Last edited by sanjuT; 08-16-2004 at 10:35 AM.

  6. #6
    Join Date
    Nov 2003
    Posts
    655
    I don't actually do classic ASP anymore, and I don't recall the details on usage of the FSO object, so you'd either need to check the documentation (best idea) or wait for someone who knows to reply.

    The logic is:
    -If directory doesn't exist
    --Create directory
    ...
    -Save to directory

    After the "if", the directory will exist (or there was an error), so you can save to it. Logically, there's no difference whether or not it existed before the "if".

    If you're saving multiple files to the same directory in a loop, put the "if" before the loop, not inside it.

  7. #7
    Join Date
    Dec 2002
    Posts
    359
    Thanks, I'll play around with it and see if i can get it to work.

    If anyone else knows, can u provide some help?

    THANKS

  8. #8
    Join Date
    Nov 2003
    Posts
    655
    Here's a reference: http://msdn.microsoft.com/library/de...ereference.asp

    MSDN is an excellent resource for MS product documentation.

  9. #9
    Join Date
    Dec 2002
    Posts
    359
    Once again u have been a great help to me!

  10. #10
    Join Date
    Nov 2003
    Posts
    655
    Glad to be of help

  11. #11
    Join Date
    Dec 2002
    Posts
    359
    shouldn't this work? it doesn't create the folder named with the value for EventID.



    objFSO.CreateFolder("C:\webapps\markEvents\UploadedFiles" & EventID)

  12. #12
    Join Date
    Nov 2003
    Posts
    655
    If nothing else, you're missing a "\" before the EventID.

    Try:

    objFSO.CreateFolder("C:\webapps\markEvents\UploadedFiles\" & EventID)

  13. #13
    Join Date
    Dec 2002
    Posts
    359
    i saw that and added the "\", but it's not working.

    i dimmed a variable, and assigned it a text value (ie "new"). i used the same syntax as above and it DID create the "new" folder, so i assume my prob is with EventID.

    it has been dimmed, and is set here:

    EventID = request.QueryString ("Event")

    this must be where my problem is.

    does that line take the value from the URL? for example, my URL would be:

    http://127.0.0.1/markEvents/uploadform.asp?Event=214

    so i would want my new folder to be named '214'

  14. #14
    Join Date
    Nov 2003
    Posts
    655
    Hmmm... I don't see anything wrong... Try doing a response.write on EventID and see if you get what you expect...

  15. #15
    Join Date
    Dec 2002
    Posts
    359
    OK, well EventID was not being passed.

    I took out this part from my form tag:

    ENCTYPE="multipart/form-data"

    and the EventID WAS passed.

    now i get this error:

    Cannot call BinaryRead after using Request.Form collection.

    i passed EventID thru a hidden field (from uploadform.asp to uploadexmple.asp):

    <INPUT type="text" ID="Event" NAME="Event" value="<%=EventID%>">

    where i set EventID as:
    EventID = request.QueryString ("Event")

    So now the info goes to uploadexmple.asp, and i attempt to retrieve EventID by:

    EventID = request("Event")

    the error occurs in another page, upload.asp (a bunch of classes):

    biData = Request.BinaryRead(Request.TotalBytes)

    I think this problem has to do with the EventID = request("Event") part.
    I remember something about not being able to use this if already used, or something like that.

    Any ideas?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles