title: Create serverfolder if filepath does not exist
body: <p>I have a controller method that handles file uploads from a jquery script. I specify the filepath with the following code <code>Path.Combine(Server.MapPath("~/UserFiles/"), qqfile);</code> I would like to add a parameter that specifies a subfolder for the file, but i can only specify existing folders. </p>
  
  <p>Is there any easy fix to create the subfolder on the server if it doesn't exist?</p>
  
  <p>This is my controller method:</p>
  
  <pre><code>public ActionResult FileUpload(string qqfile)
  {
      var file = string.Empty;
  
      try
      {
          var stream = Request.InputStream;
          if (String.IsNullOrEmpty(Request["qqfile"]))
          {
              // IE
              HttpPostedFileBase postedFile = Request.Files[0];
              stream = postedFile.InputStream;
              file = Path.Combine(Server.MapPath("~/UserFiles/"), System.IO.Path.GetFileName(Request.Files[0].FileName));
          }
          else
          {
              //Webkit, Mozilla
              file = Path.Combine(Server.MapPath("~/UserFiles/"), qqfile);
          }
  
          var buffer = new byte[stream.Length];
          stream.Read(buffer, 0, buffer.Length);
          System.IO.File.WriteAllBytes(file, buffer);
      }
      catch (Exception ex)
      {
          return Json(new { success = false, message = ex.Message }, "application/json");
      }
  
      return Json(new { success = true }, "text/html");
  }
  </code></pre>