How do I get the path lastly accessed like OpenFileDialog does?Hi all, <div><br/></div> <div>I'm using both <span style="font-family:Arial;font-size:13px;white-space:pre">OpenFileDialog and FolderBrowserDialog in my app.</span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">I found OpenFileDialog always remembers the directory path lastly accessed </span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">(I'm not setting InitialDirectory property), while FolderBrowserDialog does not.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">How do I get this path? I would like to open FolderBrowserDialog with this path set.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">Many thanks.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <hr class=sig> Jae© 2009 Microsoft Corporation. All rights reserved.Wed, 08 Jul 2009 22:29:43 Z0a38bfe1-f0b4-41cc-a89a-e657d29f72c5http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#0a38bfe1-f0b4-41cc-a89a-e657d29f72c5http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#0a38bfe1-f0b4-41cc-a89a-e657d29f72c5JaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Hi all, <div><br/></div> <div>I'm using both <span style="font-family:Arial;font-size:13px;white-space:pre">OpenFileDialog and FolderBrowserDialog in my app.</span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">I found OpenFileDialog always remembers the directory path lastly accessed </span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">(I'm not setting InitialDirectory property), while FolderBrowserDialog does not.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">How do I get this path? I would like to open FolderBrowserDialog with this path set.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre">Many thanks.</span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <div><span style="font-family:Arial;font-size:small"><span style="font-size:13px;white-space:pre"><br/></span></span></div> <hr class=sig> JaeFri, 03 Jul 2009 00:10:39 Z2009-07-03T00:16:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#f265e394-12b7-48d2-a3dd-937483bd34e0http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#f265e394-12b7-48d2-a3dd-937483bd34e0Mark Salsberyhttp://social.msdn.microsoft.com/Profile/en-US/?user=Mark%20SalsberyHow do I get the path lastly accessed like OpenFileDialog does?As far as I know, you'll need to track the last selected folder yourself.<br/><br/>You can use the FolderBrowserDialog.RootFolder and/or FolderBrowserDialog.SelectedPath properties to set the folder that will be initially selected when the dialog is opened.<br/><br/><br/>Mark<br/><hr class="sig"> Mark Salsbery Microsoft MVP - Visual C++ Fri, 03 Jul 2009 01:01:24 Z2009-07-03T01:01:24Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#38051a91-7beb-4445-90b3-ebfd4a2f5582http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#38051a91-7beb-4445-90b3-ebfd4a2f5582Tim Dawsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Tim%20DawsonHow do I get the path lastly accessed like OpenFileDialog does?OpenFileDialog doesn't explicitly remember; it just sets the Environment.CurrentDirectory and uses the current directory when it's next opened. So, if you use that when you display your FolderBrowserDialog, that should achieve the same thing.<hr class="sig">Controls for WPF, Windows Forms and Silverlight at <a href="http://www.divelements.co.uk">http://www.divelements.co.uk</a>Fri, 03 Jul 2009 08:00:59 Z2009-07-03T08:00:59Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#6a390808-7ffc-488b-8cc5-098547b150a2http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#6a390808-7ffc-488b-8cc5-098547b150a2JaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Thank you for your reply. <div><br/></div> <div>It seems, however, Environment.CurrentDirectory is always the directory where my executable is running (Debug folder). </div> <div>Any idea?</div> <div><br/></div> <div>Thanks again!</div> <div><br/></div> <div><br/></div><hr class="sig">JaeSat, 04 Jul 2009 01:58:26 Z2009-07-04T01:58:26Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#2090d474-c5a1-42ac-9cb4-7d9b4a159f34http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#2090d474-c5a1-42ac-9cb4-7d9b4a159f34Kenneth Hauglandhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kenneth%20HauglandHow do I get the path lastly accessed like OpenFileDialog does?<p>Are you draging or opening the file for the first time in your application? If you last opend you program its not so suprising....<br/><br/>Cant you store a list of open folders before you run your application? That will requre that a small application will be running all the time though....</p><hr class="sig">KennethSat, 04 Jul 2009 20:48:47 Z2009-07-04T20:48:47Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#0289b72d-9524-43e2-a433-da168a668afehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#0289b72d-9524-43e2-a433-da168a668afeJaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Hi Ken, <div><br/></div> <div>Thanks for your response. My application doesn't open any files initially, but user may (or may not) open OpenFileDialog or FolderBrowserDialog any time from the application.</div> <div><br/></div> <div>Storing (in file or registry) the folder path is a workaround here but I just want to retrieve whatever OpenFileDialog is using, since it already knows what it is.</div> <div><br/></div> <div>Thanks!</div><hr class="sig">JaeMon, 06 Jul 2009 16:55:14 Z2009-07-06T16:55:14Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#c97e3d35-403e-4f72-96d0-7296b35af4a9http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#c97e3d35-403e-4f72-96d0-7296b35af4a9Kenneth Hauglandhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kenneth%20HauglandHow do I get the path lastly accessed like OpenFileDialog does?<blockquote>OpenFileDialog doesn't explicitly remember; it just sets the Environment.CurrentDirectory and uses the current directory when it's next opened. So, if you use that when you display your FolderBrowserDialog, that should achieve the same thing. <hr class=sig> Controls for WPF, Windows Forms and Silverlight at <a href="http://www.divelements.co.uk">http://www.divelements.co.uk</a></blockquote> <br/> Hmm.. i dont understand this completely.... Ie when the OpenFileDialog opens a file... Does it store the Enviroment.CurrentDirectory in some String?<br/> <br/> it then must stor it somewhere... Or am I complitely on the wrong track here?<br/><hr class="sig">KennethMon, 06 Jul 2009 22:27:28 Z2009-07-06T22:27:28Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#99d585c0-8875-429d-940a-d1f20c7943f2http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#99d585c0-8875-429d-940a-d1f20c7943f2JaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Hi Ken, <div><br/></div> <div>Thanks again for your response.</div> <div>You are right. It seems OpenFileDialog stores it somewhere else than Environment.CurrentDirectory. I hope to know where it is. :P</div><hr class="sig">JaeMon, 06 Jul 2009 23:14:00 Z2009-07-06T23:14:00Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#afea8a71-e758-4189-bb4d-4bed1cbaa498http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#afea8a71-e758-4189-bb4d-4bed1cbaa498Tim Dawsonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Tim%20DawsonHow do I get the path lastly accessed like OpenFileDialog does?I can't believe this thread is still going. Use the code below. You will see that once a file has been picked from the OpenFileDialog, the current directory has changed. As I said before, <em>this is how it appears to &quot;remember&quot; the last folder used</em>.<br/><br/><span style="font-size:x-small"><font size=2> <p> </p> </font></span> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">OpenFileDialog</span></span><span style="font-size:x-small"> d = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">OpenFileDialog</span></span><span style="font-size:x-small">();<font size=2> <p>d.ShowDialog(</p> </font></span></p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">this</span></span><span style="font-size:x-small">);<font size=2> <p>label1.Content =</p> </font></span></p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Environment</span></span><span style="font-size:x-small">.CurrentDirectory;</span></p><hr class="sig">Controls for WPF, Windows Forms and Silverlight at <a href="http://www.divelements.co.uk">http://www.divelements.co.uk</a>Tue, 07 Jul 2009 08:59:29 Z2009-07-07T08:59:29Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#70b10a4a-54cf-4426-93c7-f2dfdbd9bee1http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#70b10a4a-54cf-4426-93c7-f2dfdbd9bee1JaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Hi Tim, <div><br/></div> <div>Environment.CurrentDirectory is initially pointing to the working directory, not the lastly accessed folder path.</div> <div>It is true that Environment.CurrentDirectory is set to whatever the directory selected by OpenFileDialog when it returns DialogResult.OK, but, before OpenFIleDialog is opened, it is still the working directory. </div> <div><br/></div> <div>What I mean by 'remember' is that OpenFileDialog knows lastly accessed folder when Environment.CurrentDirectory is still pointing to the working directory.</div> <div><br/></div> <div>So..</div> <div><br/></div> <div> <pre lang="x-c#">label1.Content = Environment.CurrentDirectory; // working directory OpenFileDialog d = new OpenFileDialog(); // d opens with lastly selected directory if(DialogResult.OK == d.ShowDialog(this)) { label1.Content = Environment.CurrentDirectory; // selected directory } else { label2.Content = Environment.CurrentDirectory; // working directory }</pre> <br/></div> <div> <p> </p> </div> <div><br/></div> <div><br/></div> <hr class=sig> JaeWed, 08 Jul 2009 21:28:06 Z2009-07-08T21:35:17Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#91f1dacf-4718-4614-ac11-e45e50145f2fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#91f1dacf-4718-4614-ac11-e45e50145f2fKenneth Hauglandhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kenneth%20HauglandHow do I get the path lastly accessed like OpenFileDialog does?Hi Jae<br/><br/>I gave up and maked a proposed answer... sorry...<br/><br/>But... I think you are right...  and I personaly thinks its stored in the registery  some place ...<hr class="sig">KennethWed, 08 Jul 2009 22:01:15 Z2009-07-08T22:01:15Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#89042d60-a33c-4d12-b6ff-fad418f8c4cdhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#89042d60-a33c-4d12-b6ff-fad418f8c4cdKenneth Hauglandhttp://social.msdn.microsoft.com/Profile/en-US/?user=Kenneth%20HauglandHow do I get the path lastly accessed like OpenFileDialog does?Hey guys... This is a direct copy from a reply from Nobugs (Hans Pessant)<br/><br/> <div class=codeseg><span style="font-family:verdana,arial,helvetica,sans-serif;font-size:x-small">Yes, if you do not set the InitialDirectory property, OpenFileDialog looks in the registry for the last path that was used to open a file.  I think the key is HKCU\ Software\ Microsoft\ Windows\ CurrentVersion\ Explorer\ Comdlg32\ OpenSaveMRU.  You shouldn't rely on this history but it is convenient to the user if you can't provide a decent InitialDirectory value.<br/><br/><a href="http://social.msdn.microsoft.com/forums/en-US/winforms/thread/94b94dc2-0460-4a1e-bdf6-7d3318b9c8ba">http://social.msdn.microsoft.com/forums/en-US/winforms/thread/94b94dc2-0460-4a1e-bdf6-7d3318b9c8ba</a><br/></span></div> <br/><br/>btw he is almost right it should be HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU<br/><br/><br/> <hr class=sig> KennethWed, 08 Jul 2009 22:10:37 Z2009-07-08T22:14:20Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#58631831-ecc2-45a3-806f-61ea486ccb1chttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0a38bfe1-f0b4-41cc-a89a-e657d29f72c5#58631831-ecc2-45a3-806f-61ea486ccb1cJaeHyeok14http://social.msdn.microsoft.com/Profile/en-US/?user=JaeHyeok14How do I get the path lastly accessed like OpenFileDialog does?Thank you Ken!!<hr class="sig">JaeWed, 08 Jul 2009 22:29:20 Z2009-07-08T22:29:20Z