title: mvc save file to folder in site
body: <p>I'm trying to save files to a folder in my site, but I keep receiving an UnauthorizedAccessException error.</p>
  
  <pre><code>   [HttpPost]
      public ActionResult Edit(Product product, HttpPostedFileBase image)
      {
          var img = Path.GetFileName(image.FileName);
  
          if (ModelState.IsValid)
          {
              if (image != null &amp;&amp; image.ContentLength &gt; 0)
              {
                  var path = Path.Combine(Server.MapPath("~/Content/productImages/"),
                                          System.IO.Path.GetFileName(image.FileName));
                  image.SaveAs(path);
                  product.ImageName = img;
  
              }
  
              // save the product
              repository.SaveProduct(product);
              // add a message to the viewbag
              TempData["message"] = string.Format("{0} has been saved", product.Name);
              // return the user to the list
              return RedirectToAction("Index");
          }
          else
          {
              // there is something wrong with the data values
              return View(product);
          }
      }
  </code></pre>
  
  <p><strong>HERE IS THE VIEW</strong></p>
  
  <pre><code>@using (Html.BeginForm("Edit", "Admin", FormMethod.Post, 
      new { enctype = "multipart/form-data" })) {
  
      @Html.EditorForModel()
  
      &lt;div class="editor-label"&gt;Image&lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @if (Model.ImageName == null) {
              @:None
          } else {
              &lt;img width="150" height="150" 
                  src="@Url.Action("GetImage", "Product", new { Model.ProductID })" /&gt;
          }
          &lt;div&gt;Upload new image: &lt;input type="file" name="image" id="image"/&gt;&lt;/div&gt;
      &lt;/div&gt;
  
      &lt;input type="submit" value="Save" /&gt;
      @Html.ActionLink("Cancel and return to List", "Index")
  }
  </code></pre>
  
  <p>I'm receiving the error on the <strong>image.SaveAs(path);</strong> line</p>
  
  <p>I can't see what exactly I'm doing wrong. Any help?</p>