473,748 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(filePat h);

I get an error about a rooted path:

There was a problem uploading the file: System.Web.Http Exception: 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 2768
<jp*******@goog lemail.comwrote in message
news:e2******** *************** ***********@34g 2000hsh.googleg roups.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().Tri m();
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\wwwr oot\myapp\image s\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'bu t 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*******@goog lemail.comwrote in message
news:10******** *************** ***********@m73 g2000hsh.google groups.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...@markNOSPA Mrae.netwrote:
<jphayc...@goog lemail.comwrote in message

news:10******** *************** ***********@m73 g2000hsh.google groups.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
14523
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 when the file is inside a shared folder on my computer. If I try to upload from any other folder it does not work. Why is this? Reason being that whenever I upload files on other forums or websites I know I don't need to have my folder shared...
14
3893
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 maxRequestLength parameter of the <httpRuntime> section and that works as expected. What I want is to enforce a max file size but haven't been able to trap the error thrown when the file is too large and that's where I could use some help.
13
4319
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 that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
8
5223
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"> <input id="MyFile" type="file" runat="server" size="50"> <asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" /> </form> .. . .and the corresponding vb.net code:
18
4349
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 get it to upload a file to the FTP server. I just get a "Cannot connect to remote server" error after this TRY: s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
4
4487
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 one of my webform pages which includes a button that pops up a window where you can upload files, if you upload files in this popup window, it seems to somehow clear out all of the session variables and the users get logged out. However, if...
8
3491
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 it to a directory and store the path to the file in the db, in addition to storing other text from other fields in the form. Then I will get that path using PHP to display the image file in a browser. First things first, I'm having difficulty...
4
6915
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 function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
3
1944
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: copy( /home/wasstech/attachement/juj.doc) : failed to open stream: Operation not permitted in /home/wasstech/public_html/send.php on line 9 Error
1
47476
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.