-1

First time posting on this forum, and also very new to coding. Sorry if this is an easy question but I'm doing all sorts of things wrong.

The situation I want to save a screenshot, and I want to filename to be the current date like:

string path = DateTime.Now.ToShortDateString().ToString();

And I'm trying this:

ScreenCapture s = new ScreenCapture();
s.CaptureWindowToFile(this.Handle,(@"C:\images\" + path + ".png"), ImageFormat.Png);

which is a mess, and doesn't work. Any help would be appreciated even if you tell me to first learn more and then start with my own projects.

EDIT: The screencapture class I used: http://www.developerfusion.com/code/4630/capture-a-screen-shot/

Martijn Nosyncerror
  • 172
  • 1
  • 3
  • 16

2 Answers2

4

You probably have invalid characters in your time string. Use:

DateTime.Now.ToString("ddMMyyHHmmss");

You can change the order as you like. The order I wrote is "day, month, year, hour, minute, second"

Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
0

you could declare your variable using the examples below

var path = DateTime.Now.ToString("ddMMyyHHmmss");

or

 string path = DateTime.Now.ToString("ddMMyyHHmmss");
MethodMan
  • 18,625
  • 6
  • 34
  • 52