Copy the file to the installation directory metro-style-app

Is there a way to copy a file (selected using filepicker) into the installdir of the current metro style application? I tried to get InstallationFolder using:

Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
Windows.Storage.StorageFolder installedLocation = package.InstalledLocation;

But when getting InstalledLocation, I always get the following error:

Error HRESULT E_FAIL has been returned from a call to a COM component.

Perhaps this is a problem with debugging the application / not installing it from the store? How to fix this exception?

A copy of the file should be possible with Windows.Storage.CopyAsync(IStroageFolder, ...). InstalledLocation is a type StorageFolder. Someone has some experience if this is allowed or I will get sth. as a security exception?

+3
source share
1 answer

InstalledLocation , (ApplicationData.Current.LocalFolder).

:

var fop = new FileOpenPicker();
fop.FileTypeFilter.Add(".txt");
StorageFile file = await fop.PickSingleFileAsync();
if (file != null)
    await file.CopyAsync(ApplicationData.Current.LocalFolder);

.

+2

All Articles