68

I am using dotlesscss for my css and I remember how to use that but what I am forgetting is how to get the root project path so that I can generate the full file path to my .less file to get for the less engine to parse. How do I get the project root path so that I can generate the path for my less files?

1 Answer 1

148
Server.MapPath("~");

or:

HostingEnvironment.ApplicationPhysicalPath 
Sign up to request clarification or add additional context in comments.

4 Comments

Better use HostingEnvironment.ApplicationPhysicalPath because HttpContext.Current.Server can be null in some circumstances -- for instance, if called from a spawned worker thread.
HostingEnvironment.ApplicationPhysicalPath is in the System.Web.Hosting namespace.
if Server.MapPath doesn't work. Try System.Web.HttpContext.Current.Server.MapPath(saveAsLocation)
Is there any way to add this code to a Web.Config file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.