Not sure if this answers your question or your problem, but the tilde (~) is a
little-known feature in ASP.NET that resolves to the application name.
In the slides from the BlackBelt WebForms talk on Scott Guthrie's page
(
http://www.scottgu.com/) you'll find some great information about dealing with
paths:
Leveraging ASP.NET Paths
Problem: How to layout web project files without messy path problems?
Example relative path issue:
<img src=“../../images/logo.gif”>
Move the page to a new directory and it fails
Leveraging ASP.NET Paths
Solution: Leverage the ASP.NET “~” feature to base server control paths on
application root directories
For example:
“~/images/image1.gif”
resolves at runtime to:
“/StoreVB/images/image1.gif”
Paths within Controls
Problem: How to manage paths to images/resources used by controls (both user
and compiled)?
Example relative path problem:
<img src=“logo.gif”> declared within user control
User control used on 2 pages in separate sub-directories:
/Foo/SubDir1/Bar.aspx
/Foo/SubDir2/Baz.aspx
Browser will resolve image reference to 2 separate directories:
/Foo/SubDir1/logo.gif
/Foo/SubDir2/logo.gif
One potential fix would be to use “~” and always expect the control’s files to
be installed in specific place under the application root
Control.ResolveUrl Method
ASP.NET method enables resolution of URLs based on the control’s location
Example:
Page at: /Store/page1.aspx
Control at: /Store/UserControls/UC1.ascx
Image at: /Store/UserControls/MyPhoto1.jpg
If control calls ResolveUrl(“MyPhoto1.jpg”) it will automatically be returned
fully qualified reference to the Image location regardless of page location
All built-in ASP.NET server controls leverage this feature.
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/security_bulletins/ms03-026.asp
I have a template in the root directory of my application and I want to use
it from an .aspx file inside some sub-folder of the root directory. The
problem is the following command:
this.Content = (Template) this.LoadControl ("/template.ascx");
I need to specify a virtual path to the .ascx file and depending on from
where I include the template, of course, that virtual path changes. How can
I determin the virtual path to my root directory or change the current
directory so that the LoadControl function will not fail?
Thank you very much.
Regards,
Felix Arends