title: Get Physical path of Virtual Directory in Window Service
body: <p>In my IIS server I have a <strong>Virtual Directory</strong> <em>("docPath")</em> which is mapped with a physical folder of my machine. </p>
  
  <p>I have a <strong>Window Service</strong> and from this service I need to get the Physical path of Virtual directory (created on IIS) i.e. <em>"docPath"</em>. </p>
  
  <p>Since this is Windows service so I do not have <strong><a href="https://msdn.microsoft.com/en-us/library/system.web.httpcontext(v=vs.110).aspx" rel="nofollow">HTTPContext</a></strong> object and I cannot use the <code>HttpContext.Current.Server.MapPath("/docPath");</code></p>
  
  <p><strong>This is what I've tried so far:</strong></p>
  
  <p>I have tried to use the <a href="https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager(v=vs.90).aspx" rel="nofollow">ServerManager</a> from <a href="https://msdn.microsoft.com/en-us/library/microsoft.web.administration(v=vs.90).aspx" rel="nofollow">Microsoft.Web.Administration</a>. </p>
  
  <pre><code>ServerManager serverManager = new ServerManager();
  Site site = serverManager.Sites.FirstOrDefault(s =&gt; s.Name == "Default Web Site");
  Application myApp = site.Applications["/docPath"];
  </code></pre>
  
  <p>But in <a href="https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager.sites(v=vs.90).aspx" rel="nofollow">Sites</a> only web application created on IIS server are coming and not Virtual directories.</p>
  
  <p>Also, <code>System.Web.Hosting.HostingEnvironment.MapPath</code> is also not working.</p>
  
  <p><strong>Could anybody let me know how can I get physical path of a Virtual Directory in Windows Service?</strong> </p>