将会话数据保存到 ApplicationData 文件夹 (Windows 7/WindowsVista/WindowsXP)

发布于 2024-08-18 20:01:44 字数 415 浏览 4 评论 0原文

我试图将会话数据保存到用户本地 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疑心病 2024-08-25 20:01:44

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文