c# - 如何在 C# 中为任何用户创建 "AppData\Roaming"中的文件文本

标签 c#

我想保存我的应用程序的日期,但我不知道应用程序是否为不同的用户保存,例如,如果“andy”我不能使用(“C:\Users\Gamemaker\AppData\Roaming”),那么如何为任何用户在“AppData\Roaming\MaxrayStudyApp”中创建文件。

    Computer myComputer = new Computer();
        myComputer.FileSystem.WriteAllText(@"C:\Users\Game maker\AppData\Roaming\MaxrayStudy\data.txt","", false);

最佳答案

几乎是这个的重复:Environment.SpecialFolder.ApplicationData returns the wrong folder

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

这应该获取您需要的文件夹,然后使用 Path.Combine() 写入该文件夹中的目录。

var roamingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var filePath = Path.Combine(roamingDirectory, "MaxrayStudy\\data.txt");

关于c# - 如何在 C# 中为任何用户创建 "AppData\Roaming"中的文件文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497835/

相关文章:

c# - 您应该在 C# 4.0 中使用重载或可选参数来声明方法吗?

c# - 使用 SQL Server 数据库文件

c# - 使用 Entity Framework 插入时有条件地设置 Identity 字段

c# - 使用 LINQ 将三个列表连接成一个会引发异常

c#数据表批处理

c# - 列表框选择器在存在欺骗时的奇怪行为

c# - 在非开发 PC 上找不到 System.Data.SQLite

C# 最佳实践 : Centralised event controller or not

C# 将一串整数拆分为 IEnumerable<int>

c# - 从代码隐藏打开新窗口