title: Get list of files for asp.net web app returning not a valid virtual path
body: <p>I am trying to get a list of files in a folder on the filesystem in my .net web app. When I run the app, I am getting an error that says that the directory "is not a valid virtual path". How do I get this to return files, that are in my WebApp's directory (they are located in {webapp root}\docs\custFiles).</p>
  
  <pre><code>try
  {
      List&lt;string&gt; custFiles = new List&lt;string&gt;();
      StringBuilder dir = new StringBuilder(@"~\docs\custFiles\");
      dir.Append(custNo + @"\");
      string directory = HttpContext.Current.Server.MapPath(dir.ToString());
      bool IsExists = System.IO.Directory.Exists(directory);
      if (!IsExists)
      {
          string[] fileList = Directory.GetFiles(directory);
          custFiles = (fileList.ToList());
      }
  
      return custFiles;
  }
  catch (Exception ex)
  {
      throw ex;
  }
  </code></pre>