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.
It depends on exactly what you want to do with the path, but the usual approach is Server.MapPath()
. For example:
YourControl.src = Server.MapPath("~/images/image1.jpg");
That will return the physical path for the specified file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With