Reputation:
I made a program to take a screenshot of the screen. How can I save the image without prompting the user for imput?
Upvotes: 0
Views: 1201
Reputation: 133995
That depends. If you want to save it to the Temp directory, you can call Path.GetTempFileName() to get a file name where you can save the file.
If there's a particular directory in which you want to save it, you can settle on a file naming convention like screenshot1, screenshot2, etc. Load the contents of the directory, find the next number in sequence, construct the filename, and save.
Upvotes: 3
Reputation: 9522
System.IO.File.WriteAllBytes(filePath, bytes)
is what you are looking for. Give it a file path and some bytes, and it will write them to that file. Without seeing what image class you are working with, I can't tell you how to extract the bytes from it.
System.IO.File.WriteAllText(filePath, text)
is also handy for writing text files if you need to do that.
Upvotes: 0