简体   繁体   English

UWP应用程序不会将文件夹复制到AppData文件夹

[英]UWP app does not copy folder to AppData folder

I have a desktop app which I am converting to UWP(Universal Windows Platform) app using MSIX packaging tool. 我有一个桌面应用程序,正在使用MSIX打包工具将其转换为UWP(通用Windows平台)应用程序。 I have resources folder for my app which is getting copied to AppData/Roaming Folder on installing the msi. 我有我的应用程序的资源文件夹,该文件夹在安装msi时被复制到AppData / Roaming文件夹。
But when I install the msix then my resources folder is getting copied to below path : 但是当我安装msix时,我的资源文件夹将被复制到以下路径:

C:\Program Files\WindowsApps\<XXXXXXXXXXXX>_2.2.1.0_x86__9r3t3jamfgx9p\**VFS\AppData**

The resources folder is having database files, log file & some important packages which I need to access from my c# code. 资源文件夹中包含数据库文件,日志文件和一些重要的程序包,我需要从我的C#代码中访问这些程序包。

I need to access the resources folder pragmatically. 我需要实用地访问资源文件夹。 How can I access this path? 如何访问此路径? Or will it get copied to some other path where I can have access 还是将其复制到我可以访问的其他路径

I have also checked the below path for resources folder but it is not there. 我还检查了资源文件夹的以下路径,但它不存在。

C:\Users\akshay.verma\**AppData\Local\Packages**\<XXXXXXX>

Please help me with how can I access my resources folder from c# code. 请帮助我如何从C#代码访问资源文件夹。

C:\\Program Files\\WindowsApps\\_2.2.1.0_x86__9r3t3jamfgx9p**VFS\\AppData** C:\\ Program Files \\ WindowsApps \\ _2.2.1.0_x86__9r3t3jamfgx9p ** VFS \\ AppData **

The above path is app's sandbox path, you could use Windows Storage ApI to access above path. 上面的路径是应用程序的沙箱路径,您可以使用Windows Storage ApI访问上面的路径。 For example: 例如:

var LocaFolder =  ApplicationData.Current.LocalFolder;

If the resource file stored in the installed location ( C:\\Users\\akshay.verma\\**AppData\\Local\\Packages**\\<XXXXXXX> ) you could acess installation folder with the following. 如果资源文件存储在安装位置( C:\\Users\\akshay.verma\\**AppData\\Local\\Packages**\\<XXXXXXX> ),则可以使用以下内容访问安装文件夹。 Then use GetFolderAsync method to get the sub folder. 然后使用GetFolderAsync方法获取子文件夹。

StorageFolder appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder Resource = await appInstalledFolder.GetFolderAsync("Resource");
var files = await Resource.GetFilesAsync();

After get the target file, you could call CopyAsync method copy the file to the destination folder. 获取目标文件后,可以调用CopyAsync方法将文件复制到目标文件夹。 And the following shows that how to copy the folder. 下面显示了如何复制文件夹。

public static async Task CopyFolderAsync(StorageFolder source, StorageFolder destinationContainer, string desiredName = null)
{
    StorageFolder destinationFolder = null;
        destinationFolder = await destinationContainer.CreateFolderAsync(
            desiredName ?? source.Name, CreationCollisionOption.ReplaceExisting);

    foreach (var file in await source.GetFilesAsync())
    {
        await file.CopyAsync(destinationFolder, file.Name, NameCollisionOption.ReplaceExisting);
    }
    foreach (var folder in await source.GetFoldersAsync())
    {
        await CopyFolderAsync(folder, destinationFolder);
    }
}

For more info please refer UWP file access permissions . 有关更多信息,请参考UWP文件访问权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM