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
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...
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