我想保存我的应用程序的日期,但我不知道应用程序是否为不同的用户保存,例如,如果“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/