locked
Extend StorageFile class to add a custom property RRS feed

  • Question

  • In my windows store app i sync with a Server and save files in this way:

    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName.Replace('/', '_'), CreationCollisionOption.GenerateUniqueName);

    var downloader = new BackgroundDownloader();

    DownloadOperation download = downloader.CreateDownload(uri, file);


    Now i want to add a metadata to the file such as the modificationDate of the file on the Server.

    How can i store this information in order to retrieve the value if i close and re-open the app? Maybe the perfect solution is to extend the StorageFile class but it is sealed

    My goal is to be synchronized with the Server of course...


    Thursday, October 17, 2013 7:51 AM

Answers

  • To set a Comment property use DocumentProperties.Comment

    Get the DocumentProperties object from file.Properties.GetDocumentPropertiesAsync(). There is a full code snippet in the DocumentProperties.Comment documentation.

    --Rob

    Wednesday, October 23, 2013 1:24 AM
    Moderator

All replies

  • A possible solution is to add the metadata in the field Comment of a file:

    List<KeyValuePair<string, object>> extraProperties = new List<KeyValuePair<string, object>>();
    extraProperties.Add(new KeyValuePair<string, object>("System.Comment", modificationDate));
    await file.Properties.SavePropertiesAsync(extraProperties);
    But this returns me an error: "Error HRESULT E_FAIL has been returned from a call to a COM component"....


    Thursday, October 17, 2013 9:40 AM
  • To set a Comment property use DocumentProperties.Comment

    Get the DocumentProperties object from file.Properties.GetDocumentPropertiesAsync(). There is a full code snippet in the DocumentProperties.Comment documentation.

    --Rob

    Wednesday, October 23, 2013 1:24 AM
    Moderator