I made a program to take a screenshot of the screen. How can I save the image without prompting the user for imput?
+1
A:
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.
Jamie Penney
2010-05-27 01:10:11
+1
A:
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.
Jim Mischel
2010-05-27 01:12:01
I'm asking about save part, not everything above.
Serg
2010-05-27 01:13:56
A reason for the downvote would be appreciated. It seems like a valid answer to the question, as asked ... before he clarified that he knew where he wanted to save it.
Jim Mischel
2010-05-27 01:14:53
I downvoted you because I asked how to save and you pretty much answered: "save it". I need to know the how of the 'saving' process.
Serg
2010-05-27 01:21:12
I don't agree this should have been downvoted. The prime purpose of the SaveFileDialog is to allow the user to generate a filename for the file in question. Lack of a dialog implies you're getting the destination directory and filename from some other means, and Jim raises interesting points. This is really a bullshit question, because all you need to do is create a FileStream with the destination filename and appropriate flags. *what* that to use for the filename is the interesting point.
Nathan Ernst
2010-05-27 01:23:44
@Nathan: Read my question again and you'll see I asked how to save a file without prompting for path. The accepted answer does just that; I fail to see how this is a bullshit 'question'.
Serg
2010-05-27 02:28:43
Actually, your question says, "without prompting the user for imput." Combined with your mention (in the question title) of not wanting SaveFileDialog displayed, I assumed you meant that you were looking for a way to automatically generate a file name.
Jim Mischel
2010-05-29 16:10:49