ASP .net current physical location

Russell picture Russell · Nov 16, 2009 · Viewed 7.2k times · Source

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.

Answer

Gonzalo picture Gonzalo · Nov 16, 2009

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