Solved

Upload a file via a web browser to the root directory

Posted on 2008-10-14
16
264 Views
Last Modified: 2010-04-06
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?
0
Comment
Question by:JodyFischer
  • 7
  • 6
16 Comments
 
LVL 28

Expert Comment

by:chilternPC
ID: 22716575
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
0
 

Author Comment

by:JodyFischer
ID: 22721977
I don't understand what you are saying.
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22723373
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
0
 

Author Comment

by:JodyFischer
ID: 22725216
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
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22725596
did you write this code?
0
 

Author Comment

by:JodyFischer
ID: 22725730
no
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22726028
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:JodyFischer
ID: 22728407
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?
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22728565
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.--------------
0
 

Author Comment

by:JodyFischer
ID: 22731496
Tried it but it didn;t work.
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22732606
where did it upload the file?
0
 

Author Comment

by:JodyFischer
ID: 22733569
it didn't. nothing happened
0
 
LVL 28

Expert Comment

by:chilternPC
ID: 22734527
can you post more of the code you used for this ?
I'll asked some others to come and help.
0
 
LVL 20

Accepted Solution

by:
Gawai earned 500 total points
ID: 22743214
Hi Jody,

change
Folder = Server.MapPath("Uploads") & "\"

to
Folder = Server.MapPath("/")
or
Folder = Server.MapPath("\") & "\"

for more info about Server.MapPath() refer
http://www.w3schools.com/ASP/met_mappath.asp

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now