File Upload Path Problem

  • Thread starter Thread starter jphaycock
  • Start date Start date
J

jphaycock

Hi

I have a webform in a sub folder called admin. The form has a file
upload control on it. I'm trying to upload an image file to the root
images folder of the app like this:

filePath = "~/images/" + myUploadControl.FileName;
myUploadControl.SaveAs(filePath);

I get an error about a rooted path:

There was a problem uploading the file: System.Web.HttpException: The
SaveAs method is configured to require a rooted path and the path bla
bla bla is not rooted.

Can anyone tell me how to do this. I've wasted an entire morning on it
and have a tight deadline looming

Thanks

John
 
What happens if you try:
filePath = Server.MapPath("~/images/" + myUploadControl.FileName);

Hi Mark Thank you for your help

That actually works Mark but I have a fresh problem now.

When the app first starts it displays an image in a literal. The url
for the image is stored in a database field in this format :
http://localhost/myapp/images/myimage.jpg

I then use code like this to get the literal to display the image:

string pageBanner = rs[1].ToString().Trim();
litIMG.Text = "<img src='" + pageBanner + "' alt='Page Banner' />";

When I upload the new image with the file upload it is getting stored
in the database like this:

C:\Inetpub\wwwroot\myapp\images\myimage.jpg

When I try to load this image into the literal like described above
the image does not render. I looked in the source code and it's
getting built properly (<img src='C:\Inetpub\wwwroot\myapp\images
\myimage.jpg'> but it isn't rendering.

Is there a way to map this absolute path back into a web path before I
send it to the literal?

Sorry for the long winded reply :)

John
 
Not as far as I know:http://www.google.co.uk/search?sourceid=navclient&aq=t&hl=en-GB&ie=UT...

Since you're already storing the absolute path in the database, why not
store the relative path too...?

Cheers Mark

I don't know why I didn't think of this sooner but I'm just saving the
filename to the database now and hard coding the path. I can do this
since the path will always be the same.

The main thing is that the fileUpload is working thanks to you.

All the best

John
 
Back
Top