title: problems copying an image and overwriting the existing one c# wpf
body: <p>I have an image control that I charge an image via a path saved in a bdd, but if I want to change the image, first I look for the new image with an openfiledialogsends me the error, [the process cannot access the file]
  this is my code</p>
  
  <pre><code>OpenFileDialog openFileDialog = new OpenFileDialog();
          openFileDialog.Multiselect = false;
          openFileDialog.Filter = "Image files (*.;*.jpg)|*.jpg;*.png|All files (*.*)|*.*";
          openFileDialog.FilterIndex = 1;
          openFileDialog.RestoreDirectory = true;
          bool? checarOK = openFileDialog.ShowDialog();
          if (checarOK == true)
          {
              try
              {
                  string archivo = openFileDialog.FileName;  //nombre archivo seleccionado
                  rtjpg.Text = archivo; //ruta de archivo seleccionado en un textbox
                  imgfoto.Source = new BitmapImage(new Uri(openFileDialog.FileName)); //coloca la imagen en un control image
              }
              catch
              {
              }
              try
              { 
                  string origPath = rtjpg.Text; //guarda la ruta original de la imagen
                  string filename = "mdk_fr_" + nid + "_" + idpac.Text + ".jpg"; //nombre que se le dara a la copia
                  string target_path = @"c:\medikfile\imagenes\"; // carpeta destino de la imagen
                  string dest_file = Path.Combine(target_path + filename); //ruta completa de la copia
                  string destPath = dest_file;
                  destruta.Text = destPath;
                  if (!File.Exists(destPath))
                  {
                      File.Delete(destPath);
                      MessageBox.Show("borrado" + destPath);
                  }
                  else
                  {
                      //                /////
                      int bufferSize = 1024 * 1024;
                      using (FileStream fileStream = new FileStream(destPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite))
                      {
                          FileStream fs = new FileStream(origPath, FileMode.CreateNew, FileAccess.ReadWrite);
                          fileStream.SetLength(fs.Length);
                          int bytesRead = -1;
                          byte[] bytes = new byte[bufferSize];
  
                          while ((bytesRead = fs.Read(bytes, 0, bufferSize)) &gt; 0)
                          {
                              fileStream.Write(bytes, 0, bytesRead);
                          }
                      }
                  }
              }
              catch (Exception im)
              {
                  MessageBox.Show("error " + im);
              }
          }
  </code></pre>