title: How to create and save a temporary file on Microsoft Azure virtual server
body: <p>I am using a <em>free</em> MS Azure virtual webserver for my site.</p>
  
  <p>On my dev machine I can successfully create a CSV file, save it to a relative temp directory, and then download it to the browser client.</p>
  
  <p>However, when I run it from the Azure site, I get the following error:</p>
  
  <blockquote>
    <p>System.IO.DirectoryNotFoundException: Could not find a part of the
    path 'D:\home\site\wwwroot\temp\somefile.csv'.</p>
  </blockquote>
  
  <p>Does the free version of Azure Websites block us from saving files to disk? If not, where are we allowed to create/save files that we generate on the fly?</p>
  
  <p><strong>Code Example</strong></p>
  
  <pre><code>private FilePathResult SaveVolunteersToCsvFile(List&lt;Volunteer&gt; volunteers)
  {
      string virtualPathToDirectory = "~/temp";
      string physicalPathToDirectory = Server.MapPath(virtualPathToDirectory);
      string fileName = "Volunteers.csv";
      string pathToFile = Path.Combine(physicalPathToDirectory, fileName);
      StringBuilder sb = new StringBuilder();
  
      // Column Headers
      sb.AppendLine("First Name,Last Name,Phone,Email,Approved,Has Background Check");
  
      // CSV Rows
      foreach (var volunteer in volunteers)
      {
          sb.AppendLine(string.Format("{0},{1},{2},{3},{4},{5},{6}",
              volunteer.FirstName, volunteer.LastName, volunteer.MobilePhone.FormatPhoneNumber(), volunteer.EmailAddress, volunteer.IsApproved, volunteer.HasBackgroundCheckOnFile));
      }
  
      using (StreamWriter outfile = new StreamWriter(pathToFile))
      {
          outfile.Write(sb.ToString());
      }
      return File(Server.MapPath(virtualPathToDirectory + "/" + fileName), "text/csv", fileName);
  }
  </code></pre>