I'm trying to save an image over a file with the same file name. When it attempts to do this is bombs out because it says either it's a general GSI+ error or the process is already in use. This makes perfect sense why it would throw those errors, but how can I overwrite the file so that it doesn't give me this problem. I've tried Opening a file stream around it then closeing it. That didn't work. I also tried useing the *bitmap variable*.Dispose() to dispose of all the resources. That didn't do anything either. Is there something else I could try? or perhaps something I'm doing wrong?


Roei BarRank #1,271 · 1.4K reputationPosted Sep 3, 2009, 1:10 PM EDT
Randell McGlynn3 reputationPosted Sep 8, 2009, 8:13 AM EDT
private void SaveFile() { // Set the bitmap object to the size of the screen bmpPicture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); // Create a graphics object from the bitmap gfxScreenShot = Graphics.FromImage(bmpPicture); // Take the screenshot from the upper left corner to the right bottom corner gfxScreenShot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y + 25, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); // Save the screenshot to the specified path that the user has chosen bmpPicture.Save(FilePath, ImageFormat.Bmp); //****THIS IS WHERE THE ERROR IS THROWN**** }