I am trying to overwrite a file with a new version inside of an AppData sub-directory.
Current process is that the user has to select the File to overwrite, and the folder directory it sits in separately so that I can add them to the future access list. Later on the user can select from a collection of images, and it's at that point that it needs to copy and overwrite the destination file. The code I've tried to do this is as follows:
// lets try to copy file to wallpaper default location.
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
var faToken = localSettings.Values["WallpaperStorageFileFAToken"] as string;
var faTokenFolder = localSettings.Values["WallpaperStorageFolderFAToken"] as string;
var destinationFile = await LoadExistingFileSelection(faToken);
var destinationFolder = await LoadExistingFolderSelection(faTokenFolder);
StorageFile movedFile = null;
try
{
movedFile = await imageFile.CopyAsync(destinationFolder, destinationFile.Name, NameCollisionOption.ReplaceExisting);
}
catch (Exception genEx)
{
//
}
The Fa
tokens are taken after an FileOpenPicker
is used by the User to get the StorageFile
and a FolderPicker
used to get the StorageFolder
for the directory of the destination.
LoadExistingFolderSelection and LoadExistingFileSelection use the following bits of code to get the StorageFiles
and StorageFolder
await StorageApplicationPermissions.FutureAccessList.GetFileAsync(faToken);
and
await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(faFolderToken);
The issue is that this line:
imageFile.CopyAsync(destinationFolder, destinationFile.Name, NameCollisionOption.ReplaceExisting);
Throws this error:
"Value does not fall within the expected range."
and that's it, literally nothing else, any thoughts would be great.