开发者

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

开发者 https://www.devze.com 2023-01-01 08:51 出处:网络
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, yo

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

精彩评论

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

关注公众号