Solved

Upload a file via a web browser to the root directory

Posted on 2008-10-14
16
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
16 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error Handler 8 38
HTML 5 Input Type Numeric 5 31
Leaflet map example works but I want to make a change to it 5 23
Error just appeared 3 21
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 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