473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File Upload Path Problem

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
Aug 12 '08 #1
4 2746
<jp*******@googlemail.comwrote in message
news:e2**********************************@34g2000h sh.googlegroups.com...
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;
What happens if you try:

filePath = Server.MapPath("~/images/" + myUploadControl.FileName);
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 12 '08 #2
What happens if you try:
>
filePath = Server.MapPath("~/images/" + myUploadControl.FileName);

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
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
Aug 12 '08 #3
<jp*******@googlemail.comwrote in message
news:10**********************************@m73g2000 hsh.googlegroups.com...
Is there a way to map this absolute path back into a web path before I
send it to the literal?
Not as far as I know:
http://www.google.co.uk/search?sourc...apPath+reverse

Since you're already storing the absolute path in the database, why not
store the relative path too...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 12 '08 #4
On Aug 12, 2:24*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<jphayc...@googlemail.comwrote in message

news:10**********************************@m73g2000 hsh.googlegroups.com...
Is there a way to map this absolute path back into a web path before I
send it to the literal?

Not as far as I know:http://www.google.co.uk/search?sourc...hl=en-GB&ie=UT...

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

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
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
Aug 12 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
8
by: Todd Acheson | last post by:
I'm having a small problem with uploading files in ASP.NET. My html page for uploading has something similar to: <form id="Form1" method="post" enctype="multipart/form-data" runat="server">...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
8
by: mpar612 | last post by:
Hello, I am a newbie to PHP, MySQL. I am trying to create a basic file upload form. I want to get that working and then I want to integrate that into a form that will rename the file and save...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
3
by: wassimdaccache | last post by:
Dear sirs, It is shame to me to say that I have been 1 week working in this problem and it is not working. I am getting this error while I am uploading a file using my website. Warning:...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.