By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,733 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

Root Relative Path Injected as String Variable

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.