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
768 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now