|
Subject:
|
FileUpload "Rooted" error
|
|
Posted By:
|
rsearing
|
Post Date:
|
2/2/2007 8:42:31 PM
|
I am trying to create a simple FileUpload control to allow a user to upload pictures to a "pictures" folder. I have to admit, I have very little experience with creating sites, and how this would work in production. I tried the below function and get the following error:
The SaveAs method is configured to require a rooted path, and the path '~/Pictures/memberback.jpg' is not rooted.
1) What am I doing wrong? 2) Is it your experience that, if I host this with a company (such as GoDaddy) do these companies usually allow for you to upload this way to a directory?
Thanks, in advance, Rob
Protected Sub uploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uploadButton.Click If FileUpload1.HasFile Then Try FileUpload1.SaveAs("~/Pictures/" & FileUpload1.FileName) Catch ex As Exception FileUploadReport.Text = "Failed because: <br/>" & ex.Message End Try Else FileUploadReport.Text = "Please select a file before clicking the Upload Button" End If End Sub
|
|
Reply By:
|
planoie
|
Reply Date:
|
2/3/2007 6:32:12 PM
|
I imagine the problem is that the SaveAs() method doesn't automatically resolve the URL you provide (because it's not a web related class). You need to pass in a resolved URL, something like this:
FileUpload1.SaveAs(Server.MapPath("~/Pictures/") & FileUpload1.FileName)
-Peter
|
|
Reply By:
|
whiterainbow
|
Reply Date:
|
7/4/2007 1:52:33 AM
|
Hey Peter,
If the folder is inside the application path, this method will work but if I'm having my storage server seperately and mapping the store folder into the application server how could I map the path in this way. I tried to store directly to the storage folder by using the url but it is throwing the same exception. Help out for the url path upload...
Thanks and Regards,
Senthil Kumar M.
|
|
Reply By:
|
planoie
|
Reply Date:
|
7/4/2007 9:05:25 AM
|
If you are saving to a known location outside of the web application then you can't map from the application path and don't need to. Just provide the proper full path to the destination.
Be sure not to confuse the term "map" this is context with the mapping of a drive in windows. The two are different. Are you referring to the former or the latter?
-Peter
|
|
Reply By:
|
whiterainbow
|
Reply Date:
|
7/20/2007 1:17:46 AM
|
Nopes, I'm not using the map path but I'm using the direct path in an UNC path. I followed all the steps to store into an UNC path. At first, I got the authentication errors so I used the credentials for the folder as well as for the application. But even after this I faced the problem that it is saying that it is not a rooted path. So I used the drive mapping but that also failed... This time I got the error that path not found or failed authentication...
Thanks and Regards,
Senthil Kumar M.
|