473,320 Members | 2,073 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.

Problem with MapPath and inheritance

Hello,
I'm having a problem using MapPath. The problem is that my
production site is www.mydomain.com, but my development site is
www.devdomain.com/myproject. In the root folder I have a base class
page, in a folder called /learn I have a page that uses my base class.
The baseclass opens a file and writes the output to the browser. It
finds the file using MapPath("/templates/header.htm"). This works fine
on the production server, however it doesn't work on the development
machine because the initial / gets interpreted as "start from the root".
If I don't put the first /, then it doesn't work either because the base
class calls mappath which maps to "/learn/templates/header.htm" which
isn't where the file is.
How can I manage this so that it works using relative paths, so I can
develop on my development machine and then publish to my production
machine?

Thank you!

David


Meet people for friendship, contacts,
or romance using free instant messaging software! See a picture you
like? Click once for a private conversation with that person!

www.SocialNetwork.com - Get free software!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
1 1075
David Berman wrote:
Hello,
I'm having a problem using MapPath. The problem is that my
production site is www.mydomain.com, but my development site is
www.devdomain.com/myproject. In the root folder I have a base class
page, in a folder called /learn I have a page that uses my base class.
The baseclass opens a file and writes the output to the browser. It
finds the file using MapPath("/templates/header.htm"). This works fine
on the production server, however it doesn't work on the development
machine because the initial / gets interpreted as "start from the root".
If I don't put the first /, then it doesn't work either because the base
class calls mappath which maps to "/learn/templates/header.htm" which
isn't where the file is.
How can I manage this so that it works using relative paths, so I can
develop on my development machine and then publish to my production
machine?


You can use the ~ notation which means 'the root folder of my app'.

so ~/folder/file.aspx

would go into your app's root directory, into the folder folder...

You might be able to do this in your MapPath directly...if not, Control
has a method called ResolveUrl which will map a ~ url to its virtual path

MapPath("~/templates/header.htm") //might work
or
MapPath(this.Page.ResolveUrl("~/templates/header.htm"))

the latter one, I assume we're inside a user control...you need a
Control to get access to that method....

--
Craig Deelsnyder
Microsoft MVP - ASP.NET
Nov 18 '05 #2

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

Similar topics

3
by: TheBob | last post by:
I have read all related posts, but still cannot solve my issue. With my database and asp page in the root folder all works fine. <% set conn=Server.CreateObject("ADODB.Connection")...
6
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
7
by: Bart | last post by:
When I try to upload a file from whithin a form, it works locally. But when i deploy my asp.net application, i got the error 'uri formats are not supported'. I thought it has something to do...
1
by: Loui Mercieca | last post by:
I have a very basic problem, but can't seem to solve it. Whenever i try to use the mappath, an error is thrown ( System.NullReferenceException: Object reference not set to an instance of an...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
3
by: Cozmo | last post by:
We have an .asp application , located in: e:\myapp In there we have directories like: e:\myapp\db e:\myapp\images e:\myapp\utils e:\myapp\working
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: asem0525 | last post by:
Hello guys, I have this kind of problem: first, the textBox tbISBN has a value that is read from the text file, but then after pressing the "Clear" button, it should be realized, and when I enter...
13
by: slinky | last post by:
I'm working on a problem with a form with 6 textboxes and a submit button for adding data to an Access database.I changed a few things and got it down to 1 error!. I have a Sub Page_Load and a Sub...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.