Skip to content

How to add functionality of "recent files used" in text editor using c#.net

miral l

Asked Jan 20, 2006, 5:03 AM EST1 answer
Share
LinkedInX
hello everybody..

can any one explain me how to  add functionality of "recent files used" in text editor using c#.net

thanks,
Miral

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Hi.

    Always when you open a file in your program, save the path of the file. When you have for example 5 path collected, abandon the oldest one. Then save the string collection using the way you wish. Always when your program starts, read the settings and dynamically build appropriate menuitems in your main menu, and register event handler (one will handle all of those items) for all of those menu items. You might want to check out some ready menuitems for needed properties, using visual designer helps in this way, too. In event handler, just read the path from menu item, and invoke you opening method.

    Easy access to settings

    If you are using C# 2.0, there's a good option for saving user setting, the Settings :) Your settings travel within the application, and you don't need to worry yourself about the reading and writing of data in some files or registry. Just remember to save your setting. For recent files, these setting is just the thing you might want.

    In Visual C# Express 2005 or Visual Studio .NET 2005, right click your project name in Solution Explorer, and select Properties. Then go to page Settings, and add a new setting, with a name RecentlyOpenedFiles and set the type to System.Collections.Specialized.StringCollection. I think you must add one line to the collection (one space will do) by pressing the ... -button because otherways you get null reference exception. You can remove that line later if needed. Close Properties and compile. Did you remember to leave the property Scope to User, didn't you?

    You can access to this RecentlyOpenedFiles collection by writing the following (this could go to your file open method):

    //here you add string
    global::YourProjectName.Properties.Settings.Default.RecentlyOpenedFiles.Add("recentPath.txt");
    //here you save the settings
    global::YourProjectName.Properties.Settings.Default.Save();

    Hope this helps, at least it helped me:)

    0