如何用C#创建appdata文件夹

好吧,我不知道如何输入这一切,所以请耐心等待。

这超出了我,我仍然是C#的新手。 我基本上需要在运行程序的当前用户的漫游应用程序数据中创建一个文件夹。 我还需要访问应用程序数据部分中的另一个文件夹,然后用我创建的应用程序数据文件夹中的文件副本替换文件。

前两个传球很简单

// The folder for the roaming current user string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // Combine the base folder with your specific folder.... string specificFolder = Path.Combine(folder, "YourSpecificFolder"); // CreateDirectory will check if folder exists and, if not, create it. // If folder exists then CreateDirectory will do nothing. Directory.CreateDirectory(specificFolder); 

在最后一次传递中,不清楚要复制文件的位置。
但是,假设您有一个名为的文件

 string file = @"C:\program files\myapp\file.txt"; File.Copy(file, Path.Combine(specificFolder, Path.GetFileName(file)); 

MSDN链接:

路径类
Environment.SpecialFolder枚举
File.Copy方法

我建议您使用独立存储,而不必担心文件的物理位置。 这是更灵活的方式 – 您只需使用Isolated Storage API,.NET框架负责物理文件所在的位置(例如,在不同的操作系统位置可能不同)。