Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the Root Directory of A Project

Status
Not open for further replies.

arduk

Programmer
Mar 16, 2003
13
AU
How do I return the root directory of the current project??

I have developed a web control that will be used on a number of pages, but it always references a file that is in the root directory of the current project (same location as web.config etc). How can I ensure that it always points back to the root directory, no matter how deep it is in the sub directory structure??

Thanks in advance for any help!!!
 
Hello arduk.

In ASP.NET, you can use ~ to point to the root folder of a web application. For example "~/web.config".
 
Hi umairms,

Thanks very much for your help - that is just what I was looking for, and works well from code.

Do you know how to do the same thing from an html page? - I want to set the <link> tag to point to a stylesheet, which will always be in the same location relative to the root directory of the current project. I know this is (should be) simple, but I think that the problem that I am having is that the virtual directory I am using is not directly under the default web site - it is one level deeper:
(ie it is sitting at:
rather than
)
And so when I reference from the route directory with
<link href=&quot;/myapp/styles.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;>
it tries to point to rather than
I know that I can change it to href=&quot;/aspx/myapp/styles.css&quot;
but then if I move the project, or point another virtual directory to it, then it won't find the style sheet.

Basically want to reference the style sheet relative to the root directory of the current project, not the root web directory, but the ~ symbol doesn't seem to work.

Thanks very much for any (more) assistance you can give me!!!
 
Well. &quot;~&quot; is supported in ASP.NET and probably undocumented (actually only place where I encountered it was a server control development book from Microsoft Press).

Definitely, ~ is NOT for your browser. :) It's processed by the ASP.NET engine.
 
Yeah - I figured that - couldn't find any documentation on ~ within VS IDE or on msdn....any ideas on how to do it html?
 
You can either try to store the prefix /aspx in web.config and require the user to modify as required while deployment.

OR

You can use some ASP.NET hyperlink control or any other function to &quot;extract&quot; the required URL. I can't give it a try, I am on a fresh installation and VS.NET is still not up :).
 
thanks for your help and your prompt replies...will give it a try!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top