Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Virtual Paths

0 views
Skip to first unread message

edx

unread,
Aug 18, 2003, 12:29:36 PM8/18/03
to
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


Ken Cox [Microsoft MVP]

unread,
Aug 18, 2003, 8:13:16 PM8/18/03
to
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

"edx" <Felix....@gmx.de> wrote in message
news:OXFysXaZ...@TK2MSFTNGP09.phx.gbl...

edx

unread,
Aug 19, 2003, 3:56:15 AM8/19/03
to
> 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:
>
> [Snip: Very helpful text on path usage]

Thank you very much, I got it to work this way. Is there a method in the
.NET Framework which allows to get the relative Path between two physical
paths? Just like:

GetRelativePath ("C:\Test\A", "C:\Test\C\");

Would return "..\C" which is the relative path if you are inside A and want
to get to C?

Thanks again for your help.
Regards,
Felix Arends


0 new messages