locked
Comparing StorageFolder Objects RRS feed

  • Question

  • Hi,

    What would be a definite way of checking equality among StorageFolder objects ?

    For instance, I display a FolderPicker on some action and store the returned StorageFolder. If the next time the user chooses the same StorageFolder, I would like to know whether its the same folder that was selected previously.

    As I understand it, we shouldn't be dealing with Path in any case as its unreliable. 

    The FolderRelativeId looks promising, but the documentation is not clear about how unique it actually is.

    Any ideas/insight?

    Wednesday, May 1, 2013 2:38 PM

Answers

  • Then I do not know if there is any other unique identifier for folder. How about create a composite key of folder name, datetime of creation, owner, and path (if not null) and compare that to determine the folder uniqueness. For practical purposes it will be very rare to have different folder having same name and datetime key. You can add other properties to key to be certain that they are different. 


    Thanks,
    Sachin
    My Samples | Personal Website

    Wednesday, May 1, 2013 5:46 PM
  • Hi Srijith,

    There is no unique ID provided for StorageItems.

    You will need to come up with your own heuristic for this. You can use the Path as part of the heuristic, but make sure to include a way to handle cases where the StorageFolder doesn't have a Path or doesn't have a unique path.

    --Rob

    Wednesday, May 1, 2013 9:02 PM
    Moderator

All replies

  • If you are saving the path for future use, try using FutureAccessList (this will given a token which will be unique). Once we add the folder to this list, we will get a token which can be stored and used to retrieve the same folder again from this list. Like you said FolderRelativeId is also one way but documentation is not very convincing about its uniqueness. 

    See this more details -> http://msdn.microsoft.com/en-us/library/windows/apps/hh972603.aspx


    Thanks,
    Sachin
    My Samples | Personal Website


    • Edited by Sachin S Wednesday, May 1, 2013 2:53 PM
    Wednesday, May 1, 2013 2:50 PM
  • Hi Sachin03,

    This would be a good enough workaround when one isn't dealing with a lot of folders and just needs to store the top-level folders picked.

    But in my scenario, I also need to check whether the StorageFolder picked the second time is a part of the folder hierarchy of the previously picked StorageFolder.

    So, I would need to add every folder in the FutureAccessList, which I'm afraid could cause it to overshoot the limit.

    Wednesday, May 1, 2013 4:23 PM
  • Then I do not know if there is any other unique identifier for folder. How about create a composite key of folder name, datetime of creation, owner, and path (if not null) and compare that to determine the folder uniqueness. For practical purposes it will be very rare to have different folder having same name and datetime key. You can add other properties to key to be certain that they are different. 


    Thanks,
    Sachin
    My Samples | Personal Website

    Wednesday, May 1, 2013 5:46 PM
  • Hi Srijith,

    There is no unique ID provided for StorageItems.

    You will need to come up with your own heuristic for this. You can use the Path as part of the heuristic, but make sure to include a way to handle cases where the StorageFolder doesn't have a Path or doesn't have a unique path.

    --Rob

    Wednesday, May 1, 2013 9:02 PM
    Moderator
  • Thanks for the confirmation, Rob. I guess a composite key with path, datetime of creation and name should cover my scenario for all practical purposes.

    If possible, could you shed some light on StorageFolder/StorageFile.FolderRelativeId ? Can that too be a part of the heuristic ? Is it guaranteed to be consistent among StorageFolder/StorageFile objects pointing to the same folder/file ?
    Thursday, May 2, 2013 4:01 AM