hello everybody..
can any one explain me how to add functionality of "recent files used" in text editor using c#.net
thanks,
Miral
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AnttiPosted Jan 21, 2006, 6:29 AM
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 stringglobal::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:)