title: ASP.NET Core 3.0 HttpContext.Current.Server.MapPath
body: <p>Im migration a classic <code>C# MVC</code> project to <code>.NET Core</code> and I have a Utility Project where I need to get access of <code>App_Data</code> folder.</p>
  
  <p>I already create in this new project my <code>App_Data</code> folder outside <code>wwwroot</code> but I need to get reference to it from this Utility Project.</p>
  
  <p><a href="https://i.stack.imgur.com/zOcca.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zOcca.png" alt="enter image description here"></a></p>
  
  <p>This is my old code:</p>
  
  <pre><code> public static class Common
      {
        private static void DeleteTestFiles()
              {
                  var path = HttpContext.Current.Server.MapPath("~/App_Data/Files");
                  .....
      }
  }
  </code></pre>
  
  <p>I was reading that in 3.0 there is a way to do this, here the example:</p>
  
  <pre><code> private readonly IWebHostEnvironment _hostingEnvironment;
  
          public HomeController(IWebHostEnvironment hostingEnvironment)
          {
              _hostingEnvironment = hostingEnvironment;
          }
  
          public ActionResult Index()
          {
              string webRootPath = _hostingEnvironment.WebRootPath;
              string contentRootPath = _hostingEnvironment.ContentRootPath;
  
              return Content(webRootPath + "\n" + contentRootPath);
          }
  </code></pre>
  
  <p>But above code is for a Controller that lives in the web project. My Utility Projects common class is not a Controller and is a static class so I cannot have constructor in order to have <code>IWebHostEnvironment</code> to be injected automaticly.</p>
  
  <blockquote>
    <p>Any clue how can I do get the path or maybe I need to manually inject IWebHostEnvironment but don't have a clue.</p>
  </blockquote>