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# - 我应该使用什么类型的集合?

c# - Xamarin:libmonosgen-2.0.dylib:MCNearbyServiceAdvertiser 上缺少所需的代码签名

c# - 为什么我需要在所有传递闭包中使用 ConfigureAwait(false)?

c# - 将最后一个值复制到其他单元格,直到我们看到一个已填充的单元格

c# - 静态方法中的全局变量

c# - 将类型作为参数传递给属性

c# - 捕获日志文件的更改

c# - 安全比较与不安全,byte[]

c# - 无法从 C# 应用程序将文件上传到 Orthanc 服务器