Click to See Complete Forum and Search --> : create new folders on the fly?


sanjuT
08-06-2004, 11:57 AM
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!!!!!!

buntine
08-06-2004, 11:37 PM
FSO has a function named 'CreateFolder()'.

Dim fso
fso = Server.CreateObject("Scripting.FileSystemObject")
fso.CreateFolder(EventID)
Regards,
Andrew Buntine.

sanjuT
08-09-2004, 09:32 AM
Thanks, but how could I incorporate this into my code?

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

CardboardHammer
08-09-2004, 09:48 AM
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.)

sanjuT
08-09-2004, 09:54 AM
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!!!

:)

CardboardHammer
08-09-2004, 10:25 AM
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.

sanjuT
08-09-2004, 10:34 AM
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

CardboardHammer
08-09-2004, 10:38 AM
Here's a reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/fsooriscriptingrun-timereference.asp

MSDN is an excellent resource for MS product documentation.

sanjuT
08-09-2004, 10:40 AM
Once again u have been a great help to me!:D

CardboardHammer
08-09-2004, 10:55 AM
Glad to be of help :cool:

sanjuT
08-10-2004, 10:03 AM
shouldn't this work? it doesn't create the folder named with the value for EventID.



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

CardboardHammer
08-10-2004, 10:22 AM
If nothing else, you're missing a "\" before the EventID.

Try:

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

sanjuT
08-10-2004, 10:34 AM
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'

CardboardHammer
08-10-2004, 10:43 AM
Hmmm... I don't see anything wrong... Try doing a response.write on EventID and see if you get what you expect...

sanjuT
08-10-2004, 11:16 AM
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?

CardboardHammer
08-10-2004, 11:19 AM
Ah... yes... now I recall that things get odd with "multipart/form-data"... lemme do a quick look-see....

EDIT: read this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnasdj01/html/asp01a2alistingb.asp

Note this part:
"'Having used BinaryRead, the Request.Form collection is
`no longer available to us. So, we have to parse the
`request variables ourselves!"

sanjuT
08-10-2004, 02:15 PM
i tried:

EventID = UploadFormRequest("Event")

but then i get an error that says UploadFormRequest is not defined.

so i dimmed it (even tho i don't think that's right) and now i get a type mismatch error.

CardboardHammer
08-10-2004, 03:14 PM
Did you check out the link in my previous post?

sanjuT
08-10-2004, 03:28 PM
ya, couldn't find the code to help me.

i think:

-------------
' grab the form boundary...
bArray = Split(Trim(ctArray(1)), "=")
Boundary = Trim(bArray(1))
'Now use that to split up all the variables!
FormData = Split(PostData, Boundary)
'Extract the information for each variable and its data
Dim myRequest, myRequestFiles(9, 3)
Set myRequest = CreateObject("Scripting.Dictionary")
-----------------
is helpful, not sure. i am looking into Scripting.Dictionary.

seems like a lot just to be able to retrieve the Event # from the URL.
Is it still considered a form object? if not i guess i can make a hidden field that stores this number.

CardboardHammer
08-10-2004, 04:34 PM
A hidden field would still be part of the form, so that won't get you anywhere, as you'd still need to parse it out... If I understand how it works correctly...

sanjuT
08-11-2004, 04:02 PM
WooHOOOOO!! got it to finally work..as usual, it wasn't too difficult, just finding the correct syntax took forever..

i used:

Set Uploader = New FileUploader

Uploader.Upload()

hh= (Uploader.Form("EventID"))

THEN:

Dim objFSO
Set objFSO= Server.CreateObject("Scripting.FileSystemObject")
'Create the folder
If Not objFSO.FolderExists("C:\webapps\markEvents\UploadedFiles\" & hh) then
objFSO.CreateFolder("C:\webapps\markEvents\UploadedFiles\" & hh)
End If

AND FINALLY:

File.SaveToDisk "C:\webapps\markEvents\UploadedFiles\" & hh

I just randomly chose 'hh'.

Thanks for all the help!
Now for my next problem.......;)

CardboardHammer
08-11-2004, 04:52 PM
You're welcome :cool: