{"id":106685,"date":"2022-05-25T07:00:00","date_gmt":"2022-05-25T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=106685"},"modified":"2022-05-25T07:05:51","modified_gmt":"2022-05-25T14:05:51","slug":"20220525-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20220525-00\/?p=106685","title":{"rendered":"How can I get my <CODE>FileSavePicker<\/CODE> to open in the same folder that was picked by the <CODE>FileOpenPicker<\/CODE> or <CODE>FolderPicker<\/CODE>?"},"content":{"rendered":"<p>Say you want your <code>File\u00adSave\u00adPicker<\/code> to default to the same folder that was picked by the <code>Folder\u00adPicker<\/code>. Or your <code>File\u00adOpen\u00adPicker<\/code> to default to the same directory that was used by the <code>FileSavePicker<\/code>. Or any combination of the above. Basically, you want all the pickers to resume where the previous one left off. How do you do that?<\/p>\n<p>By default, each picker keeps a separate history of recent locations, but you can override this by setting an explicit <code>Settings\u00adIdentifier<\/code> on the picker. We saw this earlier when we <a title=\"The SettingsIdentifier property of the various file pickers lets you give names to your pickers\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200525-00\/?p=103789\"> explored how to keep two different sets of history<\/a>, so that you could have a most recent location for, say, movie clips, and a different most recent location for background music.<\/p>\n<p>But in addition to keeping settings separate, you can use the <code>Settings\u00adIdentifier<\/code> to make them the same.<\/p>\n<p>If you give your <code>File\u00adSave\u00adPicker<\/code>, <code>File\u00adOpen\u00adPicker<\/code>, and <code>Folder\u00adPicker<\/code> the same <code>Settings\u00adIdentifier<\/code>, then they will share the same history of recent locations. Each one will resume in the location that the previous one left off.<\/p>\n<pre>async Task&lt;StorageFile&gt; LoadAsync()\r\n{\r\n  var picker = new FileOpenPicker {\r\n    SuggestedStartLocation = PickerLocationId.DocumentsLibrary,\r\n    FileTypeFilter = { \".txt\" },\r\n    <span style=\"color: blue;\">SettingsIdentifier = \"Common\"<\/span>\r\n  };\r\n  return await picker.PickSingleFileAsync();\r\n}\r\n\r\nasync Task&lt;StorageFile&gt; SaveAsync()\r\n{\r\n  var picker = new FileSavePicker {\r\n    SuggestedStartLocation = PickerLocationId.DocumentsLibrary,\r\n    FileTypeChoices = { [\"Plain Text\"] = new[] { \".txt\" } },\r\n    SuggestedFileName = \"New Document\",\r\n    <span style=\"color: blue;\">SettingsIdentifier = \"Common\"<\/span>\r\n  };\r\n  return await picker.PickSaveFileAsync();\r\n}\r\n\r\nasync Task&lt;StorageFolder&gt; PickFolderAsync()\r\n{\r\n  var picker = new FolderPicker {\r\n    SuggestedStartLocation = PickerLocationId.VideosLibrary,\r\n    FileTypeFilter = { \".txt\" },\r\n    <span style=\"color: blue;\">SettingsIdentifier = \"Common\"<\/span>\r\n  };\r\n  return await picker.PickSingleFolderAsync();\r\n}\r\n<\/pre>\n<p>You can combine this with the previous trick of keeping different pickers separate: You can have a group of pickers that all share their settings for movie clips, and another group of pickers that share their settings for background music.<\/p>\n<p><b>Bonus chatter<\/b>: The Win32 equivalent of the Windows Runtime <code>SettingsIdentifier<\/code> is <code>IFileDialog::SetClientGuid<\/code>. Call <code>IFileDialog::ClearClientData<\/code> to clean up the saved information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make them all share the same settings identifier.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-106685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Make them all share the same settings identifier.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/106685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=106685"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/106685\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=106685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=106685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=106685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}