because the graduate design project needs to remove the recent history of windows, this requires getting the Windows recent history recent. This article mainly describes the use of C # implementation to obtain recent used in the files and folders. First of all , Declare the article is mainly a combination of your own project, while the main code from the level of the blog. Thank you very much for this blogger, and also hope that you learn his article: http://www.dotblogs.com.tw/larrynung/archive/ 2012/09/27/75118.aspx one. Windows Recent history
There are things like recent items or recent in a Windows system that store the history of recently used files and folders, open the run input "recent" with the shortcut key "Windows+r" you can open the most recent browsing files and folders as shown in the following illustration:
When we browse the file, it automatically stores the history in a fast way, and Windows is automatically added to the folder to record the most recently used files or folders of the system, as well as office, Cookies and so on have corresponding recent. We can go through Environment.getfolderpath (Environment.SpecialFolder.Recent) Get the location of recent recent history for Windows, the recent path in My computer is "C:\Users\dell\AppData\Roaming\Microsoft\Windows\Recent".
At the same time, because the acquisition is simpler, it is not described in detail. Add C # Get desktop, recent, My Documents, my music, cookies, and other path reference articles http://hi.baidu.com/ysuhy/item/ B12a57d3660ccc90270ae7f9 Two. Traverse the file path in recent
when traversing the recent directory, the traversal method refers to the article "[C#][vb.net], which is up." NET shortcut (shortcut) control "Dota2.txt" shortcut (shortcut), through the target to get recent shortcut key of the original storage path.
here level up authors sort out a class that gets the original path of the file through this class implementation, right Key item "Add" class, the code is as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks; Using System.IO; Directory directory using System.Reflection; BindingFlags enum Namespace Getpathrecent {public class Recentlyfilehelper {public static string Getsho Rtcuttargetfile (String shortcutfilename) {var type = Type.gettypefromprogid ("Wscript.Shell"); Gets the Wscript.Shell type Object instance = Activator.CreateInstance (type); Create the type instance var result = type.
InvokeMember ("CreateShortcut", BindingFlags.InvokeMethod, NULL, instance, new object[] {shortcutfilename}); var targetfile = result. GetType ().
InvokeMember ("TargetPath", BindingFlags.GetProperty, NULL, result, null) as String;
return targetfile; public static ienumerable<string> Getrecentlyfiles () {var recentfolder = Environment . GetFolderPath (Environment.SpecialFolder.RecENT); Gets the recent path return to file in Directory.enumeratefiles (Recentfolder) where Path.getexten
Sion (file) = = ". Lnk" select Getshortcuttargetfile (file); }
}
}
three. Display Path ListBox1 control
Add a control listbox and FileSystemWatcher to the form (monitor file system change notifications and raise events when the directory or file changes). The specific code is as follows:
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms; namespace Getpathrecent {public partial class Form1:form {public Form1 () {Initial
Izecomponent (); }//Load form private void Form1_Load (object sender, EventArgs e) {ListBox1.Items.Clea
R ();
foreach (var file in Recentlyfilehelper.getrecentlyfiles ()) {listBox1.Items.Add (file); }//Get recent path var recentfolder = Environment.getfolderpath (Environment.SpecialFolder.Rece
NT);
Filesystemwatcher1.path = Recentfolder;
filesystemwatcher1.created + = new System.IO.FileSystemEventHandler (filesystemwatcher1_created); ///When creating files and directories in the specified path (that is, recent path) increase shortcut private void Filesystemwatcher1_created (object sender, System.IO.FileSystemEventArgs e) {listBox1.Items.Add (Recen
Tlyfilehelper.getshortcuttargetfile (E.fullpath)); }
}
}
Four. Operating results
Displays the results of the files and folders that Windows recently browsed in recent the original path run as follows:
which corresponds to the map of "one. Windows history" and can also be found that Dota2.txt is the corresponding shortcut "G:\dota2\dota2.txt" to prove the article. So we get to the recent history of windows, It is also very easy to erase the history of recent, while clearing the file records from the specified U disk can also be achieved. Similarly, if you want to remove the recent office history path to "C:\Users\dell\AppData\Roaming\Microsoft\ Office\recent ". As shown in the following illustration:
Five. Summary and thanks
The article is mainly combined with their own graduation design of the U disk to clear Windows history, Office history design completed, while viewing a lot of information and books, which gave me the most help is the level up of the article, because of this information is less, so precious. The code that declares the article mainly refers to the blog of level Up http://www.dotblogs.com.tw/larrynung/archive/2012/09/27/75118.aspx
Finally, hope that the article for everyone to help, and hope that we pay attention to the above mentioned blogger article, he wrote a lot of articles, are very useful, whether technical or theoretical. If there are errors or deficiencies in the article, please Haihan!
(By:eastmount 2014-1-19 night 4 o ' http://blog.csdn.net/eastmount)