Solved

file upload in asp.net using visual basic. Can I use a relative path instead of the actual?

Posted on 2008-10-22
6
776 Views
Last Modified: 2012-06-27
Hey Experts...

I'm trying to use a file upload in a CMS website. The below code works fine, but I'm wondering if there isn't a better/easier way to get it done.

I tried using: FileUpload1.SaveAs("~\files\"
I also tried using: FileUpload1.SaveAs("..\files\"

Neither of which worked. Is there a way to upload into that directory without using the actual folder name? I want to be able to move this to another folder later and want to use relative path if possible.
If FileUpload1.HasFile Then
            Try
                FileUpload1.SaveAs("C:\Web Sites\devBoyScouts\files\" & _
                   FileUpload1.FileName)
                Label1.Text = "File name: " & _
                   FileUpload1.PostedFile.FileName & "<br>" & _
                   "File Size: " & _
                   FileUpload1.PostedFile.ContentLength & " kb<br>" & _
                   "Content type: " & _
                   FileUpload1.PostedFile.ContentType
            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
            End Try

Open in new window

0
Comment
Question by:MHenry
[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
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 22783315
You can try
FileUpload1.SaveAs( Server.Mappath("\files\") & _
                   FileUpload1.FileName)
0
 
LVL 7

Author Comment

by:MHenry
ID: 22787980
pratima_mcs,

I'll give that a shot but I don't think it will work. The page is in the admin folder. The file folder is up one level so I need to do something like, ../files. Of course, that didn't work.

I would think...
0
 
LVL 3

Expert Comment

by:mickdoc
ID: 22797036
If I am not mistaken you MUST use an absolute path like "C:\blah blah".

I normally create a name value pair in the web.config file and just pull it from there.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 7

Author Comment

by:MHenry
ID: 22797401
mickdoc,

That's what I'm thinking too. Which really bites if you're developing in one location and moving it later. I'm just hoping there's some genius-type Expert who figured something out.

Thanks.
MH
0
 
LVL 3

Accepted Solution

by:
mickdoc earned 500 total points
ID: 22820393
I found this: http://forums.asp.net/p/1051511/1630574.aspx#1630574

I didn't think that worked (haven't tried it myself) but you can give it a go. It seemed to work for the guy that asked but I am sure I read somewhere that you must provide an exact path... hmmm, age isn't being kind to my poor brain I guess!
0
 
LVL 7

Author Closing Comment

by:MHenry
ID: 31509082
Hey mickdoc, that actually worked! Thanks for your help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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