0

I intend to keep track of the FileSystem video files with KnownFolders.VideosLibrary and also the FutureAccessList (which can make me access items outside the video library).

I want to save some data in reference to each StorageFile object being used in my app. so for that first I thought of using SavePropertiesAsync method to save metadata on properties of the storagefiles so that I can access them even if the file moves to some other location in the system, or if it gets deleted futureaccesslist will remove it automatically from itself. but I am getting ACCESS DENIED exception on SavePropertiesAsync() method. and yes I am using VideoLibrary capability in my app and I am attempting this method on a file which is within KnownFolder.VideoLibrary.

Now that saveProperties isn't working, I am thinking of creating a database in my app and track the data by using FolderRelativeId of StorageFile and tracking the data against that property, because it is unique for each file even with same names. the only limitation in this scenario is that, folder related id changes when the files moves in filesystem, which cannot be notified to my app, (unless it is running, so I may use StorageLibraryTracker api). Also if the file gets deleted, I won't know about that either.

So to summarize what is a property on a StorageFile object which I can use to sync any custom metadata, between my file and that specific video file, obviously that property should remain same for that file, irrespective of where it moves in the filesystem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75

1 Answers1

1

but I am getting ACCESS DENIED exception on savepropertiesasync() method.

This method should not throw this exception if you have enabled VideoLibrary capability. Check if your code snippet are correct, for example:

StorageFolder videofolder = KnownFolders.VideosLibrary;
StorageFile onefile = await videofolder.GetFileAsync("xxx.mp3"); 
VideoProperties properties = await onefile.Properties.GetVideoPropertiesAsync();
properties.Subtitle = "track01";
await properties.SavePropertiesAsync();

If with correct code snippet and capability enabled you still get the Access Denied exception, the reason should be that the special file is setting with read only property. Please check this by right click the file and choose Properties, see Attributes.

unless it is running, so I may use StorageLibraryTracker api

As you known ,you may use StorageLibraryChange relative APIs to tracker the file changes. Tracker the changes when the app in running should meet your requirements. But you could even know the changes when the app is not running by background tasks. You could register a StorageLibraryChangeTrackerTrigger, when changes happened it will trigger a background task.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • you are getting file with finding a file name, while in my scenario I get the files with "QueryOptionsResult.GetFilesAsync()" can that be the reason of my error? @Sunteen Wu - MSFT – Muhammad Touseef Apr 17 '18 at 06:41
  • @touseef, no, this is just a different way for getting the `StorageFile` object, it will not cause the exception. Please check the file is it is read only as I mentioned in my reply. – Sunteen Wu Apr 17 '18 at 07:55
  • Yes I just checked it, I can confirm that the file throwing the exception is not read only. and it is very first file in my library, – Muhammad Touseef Apr 17 '18 at 08:30
  • I even tried it with filepicker still getting : System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))' – Muhammad Touseef Apr 17 '18 at 08:37
  • @touseef, in that case, please also check if the folder is read only. And if you still have issues, please provide a [mcve], we will test it on our side. – Sunteen Wu Apr 17 '18 at 08:43
  • I did get a sample from someone and that sample is working fine on my machine. I guess there is something unknown to me which is being done within my app which is causing this exception :/ – Muhammad Touseef Apr 17 '18 at 08:50
  • I was tried to create a simpler minimal reproduction of the problem in my project so I started to delete a lot of stuff from my app. and now the problem is gone, and I don't knw wht service was causing the problem, but seems like one of the components was the reason. thanks a lot for the help though. but I think I need to do a detail analysis of my project to find out the bug :) – Muhammad Touseef Apr 17 '18 at 09:34