Link to home
Start Free TrialLog in
Avatar of JodyFischer
JodyFischer

asked on

Upload a file via a web browser to the root directory

If I want to upload a file to a spefic directory (lets say uploads) the following code works perfectly

' Grab the file name
FileName = Upload.Fields("File1").FileName

' Get path to save file to
Folder = Server.MapPath("Uploads") & "\"

' Save the binary data to the file system
Upload("File1").SaveAs Folder & FileName

' Release upload object from memory
Set Upload = Nothing


How do you do it if you want the file in the root directory?
Avatar of Peter Hart
Peter Hart
Flag of United Kingdom of Great Britain and Northern Ireland image

I utry..
Dim fs, folder
     
   Set fs = CreateObject("Scripting.FileSystemObject")
     Set folder = fs.GetFolder("/")

or is it

Set folder = fs.GetFolder(".")


and the code has to reside in the root directory
Avatar of JodyFischer
JodyFischer

ASKER

I don't understand what you are saying.
sorry - what I mean is I would try the following code:
....................
Dim fs, folder
  Set fs = CreateObject("Scripting.FileSystemObject")
   Set folder = fs.GetFolder("/")
....................
and the code has to reside in the root directory
Sorry for not understanding, but where would it go within this code?

 Grab the file name
FileName = Upload.Fields("File1").FileName

' Get path to save file to
Folder = Server.MapPath("Uploads") & "\"

' Save the binary data to the file system
Upload("File1").SaveAs Folder & FileName

' Release upload object from memory
Set Upload = Nothing
did you write this code?
no
it would be easier to use code the already works, than to bodge something written some time ago.
see :  http://www.freeaspupload.net/
its free and r4esady to integrate into your web pages.

I use code from dmxzone.com

The code above works perfectly in a sub folder. I just need to know how to make it go into the root directory. Can you help me with this or point me to someone who can?
use this:

' Grab the file name
FileName = Upload.Fields("File1").FileName

' Get path to save file to
Folder = Server.MapPath("\")

' Save the binary data to the file system
Upload("File1").SaveAs Folder & FileName

' Release upload object from memory
Set Upload = Nothing

-----------the code has to be in the root folder.--------------
Tried it but it didn;t work.
where did it upload the file?
it didn't. nothing happened
can you post more of the code you used for this ?
I'll asked some others to come and help.
ASKER CERTIFIED SOLUTION
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial