Search code examples
c#uwpwindows-10-universalwindows-10-mobile

ImageProperties.SaveImagePropertiesAsync() doesn't save changes


I'm trying to save some properties into an image file in a Windows 10 UWP application, on the mobile phone.

var fileProperties = await file.Properties.GetImagePropertiesAsync();

fileProperties.Rating = 25;
fileProperties.Title = "Title";
fileProperties.DateTaken = DateTime.Now;

await file.Properties.SavePropertiesAsync();

For some reason, the properties are not saved.

The file is created beforehand like this:

var file = await _sourceFolder.CreateFileAsync(pathToFile, CreationCollisionOption.ReplaceExisting);
await bitmap.SaveToStorageFile(file);

where bitmap is of type WriteableBitmap. The image is saved to a file, but the properties are not.

Does anyone know what I'm not doing correctly? There is no exception, no message about why it doesn't succceed.


Solution

  • The problem here is the StorageFile.Properties.SavePropertiesAsync, which get the StorageItemContentProperties. And it use the original data to save to the file.

    You should be able to use the ImageProperties.SavePropertiesAsync method. It use new ImageProperties data to save to the file.

    For example:

    var fileProperties = await file.Properties.GetImagePropertiesAsync();
    fileProperties.Rating = 25;
    fileProperties.Title = "title";
    fileProperties.DateTaken = DateTime.Now;
    await fileProperties.SavePropertiesAsync();