1

I need to access the folder in ~/Templates in my application. I didn't get the suggestion for server.MapPath. Why so?

Also, I tried using the HostingEnvironment.MapPath and System.Web.HttpContext.Current.Server.MapPath.But it returns null. Is there any solution for this?

var path = System.Web.HttpContext.Current.Server.MapPath("~/Templates");
Matt
  • 1,245
  • 2
  • 17
  • 32
Haritha Es
  • 185
  • 3
  • 11
  • 1
    Just to get the basics straight: *does* this run in an HttpContext, that is: because of a request to a web application? – Hans Kesting Apr 18 '19 at 06:16
  • 1
    Ideally, have the consuming application *tell* the class library where the templates to use are located. Don't try to *detect* the environment you're running in. – Damien_The_Unbeliever Apr 18 '19 at 06:57
  • 1
    FYI: The "Server" in `Server.MapPath(..)` is not a global object but a [property](https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.server) of the Page class. So outside of a page (or usercontrol) it does not exist - that's why you "didn't get the suggestion" – Hans Kesting Apr 19 '19 at 07:06

0 Answers0