将会话数据保存到 ApplicationData 文件夹 (Windows 7/WindowsVista/WindowsXP)
我试图将会话数据保存到用户本地 ApplicationData 文件夹中,但 Windows 似乎只是创建了一个新的 ApplicationData 文件夹,其中的文件位于任何需要的位置。有时它会出现在我的桌面上,有时会出现在其他地方。 (例如 bin 文件夹)。
这没有任何意义。
我知道它会由于权限不足等而重定向,但这太可怕了。
有人可以告诉我这是否是将一些文本文件信息保存到我的应用程序 AppData 文件夹的正确方法?
File.WriteAllText(
Environment.SpecialFolder.ApplicationData +
"\\MyApplicationNameFolder\\" +
filename + ".txt");
I am trying to save session data to the users local ApplicationData folder, but it Windows just seems to create a new ApplicationData folder with the files inside it wherever it wants. Sometimes it ends up on my desktop, and sometimes it's elsewhere. (like the bin folder, for example).
It doesn't make any sense.
I know that it redirects due to insufficient permissions etc but this is just horrible.
Can somebody please tell me if this is the right way to save some text file info to my applications AppData folder?
File.WriteAllText(
Environment.SpecialFolder.ApplicationData +
"\\MyApplicationNameFolder\\" +
filename + ".txt");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Environment.SpecialFolder 是一个枚举,表示请求路径时需要使用的常量。它不给你路径。
使用 GetFolderPath 与该枚举值来获取路径。
Environment.SpecialFolder is an enumeration representing the constants you need to use when requesting the path. It doesn't give you the path.
Use GetFolderPath with that enumeration value to get the path.