473,386 Members | 1,810 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,386 software developers and data experts.

Root Relative Path Injected as String Variable

Put another way, is there any way I can tell ASP.NET to convert a path
(imbedded in a string variable, "~/images/some_image.gif") to a
root-relative path, that the client will understand, for the *current* page
request?

Here's what I'm doing: I am injecting HTML directly into ASPX pages via
LiteralControl.

something like this...

string myHTMLString =
"<table><tr><td>~/images/some_image.gif</td></tr></table>
litMyLiteral.Text = myHTMLString;

Notice that there is a path to an image in that HTML Table.

As shown, that path to the image obviously won't work because browsers
don't resolve "~" to the root, and ASP.NET doesn't get the opportunity to
convert that to a root-relative path that the client will understand because
it's just a string value from ASP.NET's point of view.
So, how can I have specify the root relative path correctly when injecting a
path (as a string) into a Literal - WHERE that Literal control may be on
ASPX pages in a variety of locations below the site root (i.e, the aspx
pages cannot be assumed to always exist at the root or any level below the
root)?

Thanks.
Nov 19 '05 #1
2 2286
Do a search and replace?

litMyLiteral.Text = myHtmlString.Replace("~", Request.ApplicationPath);

or create a custom server control that does it for you..

public class MyLiteral : Literal{
protected override void Render(HtmlTextWriter writer){
if (Text != null){
Text = Text.Replace("~", REquest.applicationPath);
base.Render(writer)
}
}
}

or sumtin..

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jordan Richard" <A@B.NET> wrote in message
news:OE**************@TK2MSFTNGP14.phx.gbl...
Put another way, is there any way I can tell ASP.NET to convert a path
(imbedded in a string variable, "~/images/some_image.gif") to a
root-relative path, that the client will understand, for the *current*
page request?

Here's what I'm doing: I am injecting HTML directly into ASPX pages via
LiteralControl.

something like this...

string myHTMLString =
"<table><tr><td>~/images/some_image.gif</td></tr></table>
litMyLiteral.Text = myHTMLString;

Notice that there is a path to an image in that HTML Table.

As shown, that path to the image obviously won't work because browsers
don't resolve "~" to the root, and ASP.NET doesn't get the opportunity to
convert that to a root-relative path that the client will understand
because it's just a string value from ASP.NET's point of view.
So, how can I have specify the root relative path correctly when injecting
a path (as a string) into a Literal - WHERE that Literal control may be on
ASPX pages in a variety of locations below the site root (i.e, the aspx
pages cannot be assumed to always exist at the root or any level below the
root)?

Thanks.

Nov 19 '05 #2
You'll need to call Control.ResolveUrl on the "~/images/foo.jpg" piece first.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Put another way, is there any way I can tell ASP.NET to convert a path
(imbedded in a string variable, "~/images/some_image.gif") to a
root-relative path, that the client will understand, for the *current*
page request?

Here's what I'm doing: I am injecting HTML directly into ASPX pages
via LiteralControl.

something like this...

string myHTMLString =
"<table><tr><td>~/images/some_image.gif</td></tr></table>
litMyLiteral.Text = myHTMLString;

Notice that there is a path to an image in that HTML Table.

As shown, that path to the image obviously won't work because
browsers
don't resolve "~" to the root, and ASP.NET doesn't get the opportunity
to
convert that to a root-relative path that the client will understand
because
it's just a string value from ASP.NET's point of view.
So, how can I have specify the root relative path correctly when
injecting a
path (as a string) into a Literal - WHERE that Literal control may be
on
ASPX pages in a variety of locations below the site root (i.e, the
aspx
pages cannot be assumed to always exist at the root or any level below
the
root)?
Thanks.


Nov 19 '05 #3

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

Similar topics

2
by: Scott Simpson | last post by:
Can you query from a non-root node using XPathAPI's function selectNodeList(Node contextNode, java.lang.String str)? I'm trying this using the XPath expression "//*" and I'm getting nothing back. I...
5
by: Jonathan | last post by:
I am creating a CD-ROM based website template. Things work fine under Windows but when I try to run the site under Linux the path is messed up. Therefore my JavaScript functions misinterpret the...
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
4
by: Win, Pats | last post by:
I have a snippet of HTML that I inject into a number of pages throughout my Web site at runtime. My problem is that I'm not getting the image to appear in all documents into which this snippet is...
19
by: Steve Franks | last post by:
I am using VS.NET 2005 beta 2. When I run my project locally using the default ASP.NET Development Web Server it runs using a root address like this: http://localhost:11243/testsite/ However...
8
by: Paul Bromley | last post by:
I am trying to get somewhere with user controls and have come up against an obstacle with using relative paths. I have a dataset in my user control, and have tried to enter the path with the...
15
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.