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
774 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 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