How to do it?
I don't want to use this:
HttpContext.Current.Server.MapPath   Is there a similar function that I can call without requiring a httpcontext?
For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it from a shared var.
Use the HttpRuntime.AppDomainAppPath property.
There are several options:
HttpRuntime.AppDomainAppPath
    WebApplication     -> Web root folder     UnitTest           -> ArgumentNullException     ConsoleApplication -> ArgumentNullException   AppDomain.CurrentDomain.BaseDirectory
    WebApplication     -> Web root folder     UnitTest           -> ...\AppDir\bin\Debug     ConsoleApplication -> ...\AppDir\bin\Debug   HostingEnvironment.ApplicationPhysicalPath
    WebApplication     -> Web root folder     UnitTest           -> null     ConsoleApplication -> null   I would recommend to use AppDomain.CurrentDomain.BaseDirectory, because it can be used in any type of project and it can be set up.
You can for example set UnitTest BaseDirectory to point your web root folder the AppDomain.CurrentDomain.BaseDirectory by command:
AppDomain.CurrentDomain.SetData("APPBASE", "path to your web root"); 
                        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