title: Delete image from path
body: <p>What do I need to do to end imagePath process? </p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>The process cannot access the file
    'C:\Users\Rafal\7074edcf-8849-4ea7-a87d-e2e8b5890f3f.jpg' because it
    is being used by another process.</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/SEJAX.jpg" alt="enter image description here"></p>
  
  <pre><code>public WrappedJsonResult2 UploadImageSmall(HttpPostedFileWrapper imageFile2)
          {
  
              if (imageFile2 == null || imageFile2.ContentLength == 0)
              {
                  return new WrappedJsonResult2
                  {
                      Data = new
                      {
                          IsValid = false,
                          Message = "Nie dodano zdjęcia",
                          ImagePath = string.Empty
                      }
                  };
              }
  </code></pre>
  
  <p>here I have fileName and imagePath for first picture</p>
  
  <pre><code>            var fileName = String.Format("{0}.jpg", Guid.NewGuid().ToString());
              var imagePath = Path.Combine(Server.MapPath(Url.Content("~/Content/UserImages")), fileName);
  </code></pre>
  
  <p>here I have fileName and imagePath for second picture </p>
  
  <pre><code>            var fileNameZmniejszony = String.Format("{0}.jpg", Guid.NewGuid().ToString());
              var imagePathZmniejszony = Path.Combine(Server.MapPath(Url.Content("~/Content/UserImages")), fileNameZmniejszony);
  </code></pre>
  
  <p>I save picture from JSON</p>
  
  <pre><code>            imageFile2.SaveAs(imagePath);
  </code></pre>
  
  <p>I take picture from direction of imageFile2</p>
  
  <pre><code>            var image = Image.FromFile(imagePath);
  </code></pre>
  
  <p>I scale new picture and save as second Image</p>
  
  <pre><code>            var newImage = ScaleImage(image, 300, 400);
              newImage.Save(imagePathZmniejszony);
  </code></pre>
  
  <p>Here I would like to delete file with directory first image</p>
  
  <pre><code>            if (System.IO.File.Exists(imagePath))
              {
                  System.IO.File.Delete(imagePath);
              }
  
              var model = new StronaGlowna();
              if (!TryUpdateModel(model))
              {
              }
              model.MaleZdjecie = String.Format("~/Content/UserImages/{0}", fileNameZmniejszony);
  
              return new WrappedJsonResult2
              {
                  Data = new
                  {
                      IsValid = true,
                      Message = string.Empty,
                      ImagePath = Url.Content(String.Format("~/Content/UserImages/{0}", fileNameZmniejszony))
                  }
              };
          }
  </code></pre>
  
  <p>Why I have got problem with process because this take process (HttpPostedFileWrapper imageFile2)</p>
  
  <p>and dispose() will not work for this problem. </p>