gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:58:21 33 4
gpt4 key购买 nike

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

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com