如何使用我的 Win10 应用程序打包 json 文件,使其在 LocalState(或子)文件夹中显示为独立文件?我需要我的应用程序能够偶尔更新此文件。
如果这是不可能的,应用程序可以在安装过程中将文件放在某个应用程序数据文件夹中吗?
您可以将该文件标记为“内容”和“始终复制”,并且在应用程序启动时,您可以以编程方式将其复制到 LocalFolder,然后随时更新它。
例如:假设您在根项目下有一个“Config”文件夹,而 test.json 是您要替换的文件
string testPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.json");
if (!File.Exists(testPath))
{
string tempPath = "ms-appx:///Config/test.json";
Uri location = new Uri(tempPath, UriKind.Absolute);
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(location);
await file.CopyAsync(ApplicationData.Current.LocalFolder);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句