title: How do you create folders and specify access permissions on them at the same time?
body: <p>I have a windows forms application which serves as a sort of administrative module for an ASP.NET web application. The web application serves multiple countries, and folders are created when new countries are added to the application data.</p>
  
  <p>Unfortunately on the newly added countries I run into an exception with the web application when I go and try to write files in the folders:</p>
  
  <pre><code>System.UnauthorizedAccessException: Access to the path 'C:\...' is denied.
  </code></pre>
  
  <p>With the web application using ASP.NET impersonation, it's obvious that the default IIS user (MACHINENAME\IUSR_MACHINENAME) has no permissions to write into the folder.</p>
  
  <p>How do I grant permission the the default IIS user upon folder creation?</p>
  
  <p>I understand that</p>
  
  <pre><code>System.IO.Directory.CreateDirectory(string path, DirectorySecurity directorySecurity)
  </code></pre>
  
  <p>should do this, but I don't understand how to specify the log on name on the <code>DirectorySecurity</code> object.</p>