Monday, May 07, 2012

How to make sure FolderPicker.SuggestedStartLocation work every time ?

Windows Metro style application provide a class : FolderPicker for application to select a target folder, it provide a standard interface for end user to select a folder for further operation.

By assign SuggestedStartLocation, we could ask FolderPicker to default at an assigned location for user to browse.

However, by default, FolderPicker will remember where user selected last time, and start at last location, ignore the assignment of  SuggestedStartLocation.


Check MSDN documents, it seems that the property of settingsidentifier could do some trick :

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.folderpicker.settingsidentifier.aspx


After I assign this property before call PickSingleFolderAsync, the problem solved, FolderPicker start at suggestedStartLocation each time when it show up :

folderPicker.SettingsIdentifier = DateTime.Now.ToString("HH:mm:ss tt");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();


Use DatTime.Now.ToString just to make sure the string assigned is different every time, should be easy to replace with another solution.

No comments: