title: C# - The process cannot access the file because it is being used by another process
body: <pre><code> public static void CopyImage(Image picToSave, string name)
      {
          if (picToSave.Source != null)
          {
              BitmapImage src = (BitmapImage)picToSave.Source;
              if (!Directory.Exists("Images"))
              {
                  Directory.CreateDirectory("Images");
              }
  
              FileStream stream = new FileStream("Images/" + name + ".jpg", FileMode.Create);
              JpegBitmapEncoder encoder = new JpegBitmapEncoder();
              encoder.Frames.Add(BitmapFrame.Create(src));
              encoder.Save(stream);
              stream.Close();
          }
  
  
  
      }
  </code></pre>
  
  <p>The problem occurs when i choose a file which already exists in the /Images directory, i guess it just cant overwrite, The exception is thrown at the "FileStream"" line (FileMode.Create I guess).</p>
  
  <p>If i Choose a file which isn't in the /Images directory it works fine and copies the file to the Images Directory like it should.. </p>
  
  <p>Thank you :)</p>