I am looking to add a recent files list to an application I am writing. I was thinking of adding the recent files to an xml file.
Where should this file be stored? And how should it be called from the code?
I would imagine the xml would be stored in the same folder that the application is installed in, but not everybody will install the application in the same directory.
Is there a way to code it in such a manner that it will always be stored in the same folder as the application will be installed in?
much thanks in advance!
Here is an example using
My.Settings
. It requires you to open the Settings page of the project properties and add a setting of typeStringCollection
namedRecentFiles
as well as aToolStripMenuItem
with the text "Recent".Note that the
Load
event handler includes a bit of code to allow for the fact that a setting of typeStringCollection
will beNothing
until you assign something to it. If you want to avoid having to do that in code, do the following.Value
field and click the button with the ellipsis (...) to edit.OK
. Notice that some XML has been added that includes the item(s) you added.That XML code will cause a
StringCollection
object to be created when the settings are first loaded, so there's no need for you to create one in code.EDIT:
I tested that by adding the following code:
I was able to add ten files to the list via that
Button
and then they started dropping off the end of the list as I added more. If I re-added one that was already in the list, it moved to the top. If I closed the app and ran it again, the list persisted.