0

My problem is that this try fails (resulting in the catch) on only one computer, even using the same user account. It runs fine and saves screenshots from every other computer that uses the program.

Also, manually saving a file (through explorer) into the directory works.

try
{
    Bitmap screenShot = new Bitmap(screenWidth, screenHeight);
    Graphics gfx = Graphics.FromImage((Image)screenShot);
    gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));

    imageSavePath = @"\\navy\data\Docs\PRE\LogSite\Screenshots\" + DateTime.Now.ToString().Replace('/', '-').Replace(':', '-') + ".png";
    screenShot.Save(imageSavePath, ImageFormat.Jpeg);
}
catch (Exception e)
{
    MessageBox.Show("Error saving screenshot\n\n" + e.ToString());
}

This is the error: Error Image

EDIT: The exe is running from a network drive

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
kschieck
  • 1,407
  • 2
  • 16
  • 29
  • instead of showing the whole exception message, show the imagepath. Would be a lot more useful – Sayse Apr 25 '13 at 17:43
  • In the MessageBox? the thing is it works on other computers consistently, so how could that be a problem? – kschieck Apr 25 '13 at 17:48
  • I think the application may not have permission to write to the folder, have you tried running as administrator? – Sayse Apr 25 '13 at 17:49

1 Answers1

0

I have edit my answer. Base on the code, you are trying save to Network share folder I believe you should use impersonate to resolve permission issue.

Please reference the link below.

Need Impersonation when accessing shared network drive

Community
  • 1
  • 1
Tim Phan
  • 311
  • 1
  • 11
  • how? FileIOPermission has absolutely nothing to do with how its saved – Sayse Apr 25 '13 at 17:48
  • There have only been problems on this computer. Many other computers (Using the same user) running the same code work fine. – kschieck Apr 25 '13 at 18:18