简体   繁体   中英

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. I have resources folder for my app which is getting copied to AppData/Roaming Folder on installing the msi.
But when I install the msix then my resources folder is getting copied to below path :

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.

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:\\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. 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. Then use GetFolderAsync method to get the sub folder.

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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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