tags:

views:

174

answers:

2

Hi I am developing an ASP.net web application. I need to find the current location (physical) of the web site (or the bin directory containing the assemblies).

I have tried using Directory.GetCurrentDirectory() and that returns me the ASP .net temporary directory.

I really don't like the idea of include an application setting for the absolute path in my config file (eww!)

Any help would be much appreciated! :)

Conclusion:

I should have given some context as to Why I would like the physical file path. Thanks guys for your prompt responses to the question :)

I am using XSL-FO for .net (the FO.net library) to generate a PDF. Embedding images in FO requires an absolute path to be given:

<fo:external-graphic src="C:\MyWebsite\images\image1.jpg" />

What I needed to do was set the current directory to the web site (or bin directory), which would allow the XSL FO renderer to know where to find the image.

+8  A: 

You need System.Web.HttpRuntime.BinDirectory (physical path to the bin folder) and System.Web.HttpRuntime.AppDomainAppPath (physical path to the top-level ASP.NET application folder).

Gonzalo
Thanks Gonzalo, that works great in my situation. :)
Russell
Yeah, thanks for showing these two references :)
Chau
+2  A: 

It depends on exactly what you want to do with the path, but the usual approach is Server.MapPath(). For example:

string path = Server.MapPath("pages/mypage.aspx");

That will return the physical path for the specified file.

RickNZ
Hi Rick, thanks MapPath is a handy method to be aware of, however it doesn't really fit in with my situation. I am about to update my question with some more detail on why to give some context, sorry I should have done this in the first place. Thanks for your help :)
Russell