Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
781 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
  • 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
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.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview

963 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