开发者

How can I save something without showing a SaveFileDialog()?

I made a program to t开发者_StackOverflow社区ake a screenshot of the screen. How can I save the image without prompting the user for imput?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜