File Upload. Root Path.

S

shapper

Hello,

I am uploading a file as follows:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

If FileUpload1.HasFile Then
FileUpload1.SaveAs("~\Temporary\" + FileUpload1.FileName)
Label2.Text = "File Uploaded: " + FileUpload1.FileName
Else
Label2.Text = "No File Uploaded."
End If

I get the following error:

The SaveAs method is configured to require a rooted path, and the path
'~\App_Temporary\Red Ceiling Lamp 04 [By27] [Free].jpg' is not rooted.

I know this means I should have SaveAs("C:\...")

But I also know that Temporary is in the same folder then the Aspx
file that has the FileUpload.

Can't I get that root?

Thanks,

Miguel
 
G

George Ter-Saakov

Try
FileUpload1.SaveAs(Server.MapPath("~\Temporary\" + FileUpload1.FileName))

George.
 
S

shapper

Try
FileUpload1.SaveAs(Server.MapPath("~\Temporary\" + FileUpload1.FileName))

George.


I am uploading a file as follows:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
If FileUpload1.HasFile Then
FileUpload1.SaveAs("~\Temporary\" + FileUpload1.FileName)
Label2.Text = "File Uploaded: " + FileUpload1.FileName
Else
Label2.Text = "No File Uploaded."
End If
I get the following error:
The SaveAs method is configured to require a rooted path, and the path
'~\App_Temporary\Red Ceiling Lamp 04 [By27] [Free].jpg' is not rooted.
I know this means I should have SaveAs("C:\...")
But I also know that Temporary is in the same folder then the Aspx
file that has the FileUpload.
Can't I get that root?

Miguel

Thanks,

It worked.

Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,749
Members
45,733
Latest member
MariaQch13

Latest Threads

Top