C# 桌面参考
我正在使用文件流写出文件。
我希望能够将文件写入桌面。
如果我有类似的东西,
tw = new StreamWriter("NameOflog file.txt");
我希望能够在文件名前面标识某种@desktop,它会自动插入桌面路径。
C#中存在这个吗? 或者我是否必须逐台计算机(或逐个操作系统)寻找桌面路径?
I am using a file stream to write out a file.
I was hoping to be able to write the file to the desktop.
If I have something like
tw = new StreamWriter("NameOflog file.txt");
I would like to be able to have some sort of @desktop identified in front of the file name that would automatically insert the path to the desktop.
Does this exist in C#? Or do I have to look for desktop paths on a computer by computer (or OS by OS) basis?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
快速谷歌搜索揭示了这一点:
编辑:这适用于Windows,但Mono 也支持。
Quick google search reveals this one:
EDIT: This will work for Windows, but Mono supports it, too.
您想要使用 Environment.GetFolderPath,传入 < a href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx" rel="noreferrer">
SpecialFolder.DesktopDirectory
。还有
SpecialFolder.Desktop
代表逻辑桌面位置 - 但尚不清楚两者之间的区别是什么。You want to use Environment.GetFolderPath, passing in
SpecialFolder.DesktopDirectory
.There's also
SpecialFolder.Desktop
which represents the logical desktop location - it's not clear what the difference between the two is though.就像是:
Something like:
你想要Environment.SpecialFolder
You want Environment.SpecialFolder
是的。
您可以使用环境变量。
喜欢
,但我不建议自动将日志文件写入用户桌面。
您应该将该文件的链接添加到开始菜单文件夹中。
甚至将它们填充到事件日志中。 (好多了)
yep.
you can use environmental variables.
like
but i would not recommend to automatically write a log file to the users desktop.
you should add the link to the file to your start menu folder.
or even populate them in the event log. (much better)
我也使用上面提到的方法。
但这里有几个不同的选项也有效(只是为了有一个更全面的列表):
然后:
I also use the method mentioned above.
But here are a couple different options that work too (just to have a more comprehensive list):
Then: