?
Solved

Upload a file via a web browser to the root directory

Posted on 2008-10-14
16
Medium Priority
?
273 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
14 Comments
 
LVL 29

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 29

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 29

Expert Comment

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

Author Comment

by:JodyFischer
ID: 22725730
no
0
 
LVL 29

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
 

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 29

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 29

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 29

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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

850 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