If you do not know the concept of Windows 7 library, read this article first: Windows 7 new function: Library)
The following is a quick reference for some common Windows 7 library functions, using the Windows API code pack.
This articleArticleInCodeMembers from the Aaron and SELA teams.
Each Windows 7 library is represented by an XML file with the extension. Library-MS.
Common library files are usually stored in: C: \ Users \ <username> \ appdata \ roaming \ Microsoft \ Windows \ libraries \.
For example, you can use the image library as follows:
1 Libraryname = Pictures
2 Locationpath = C: \ Users \ < Username > \ Appdata \ roaming \ Microsoft \ Windows \ libraries \
Note: You can create a library file anywhere, not necessarily in the preceding folder.
Function:
Create a new database:
1 Shelllibrary =
2 New Shelllibrary (libraryname, locationpath, overwriteexisting );
Add a folder to an existing Library:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. Add (foldertoadd );
5 }
Delete a folder from the Library:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. Remove (foldertoremove );
5 }
Enumeration library Folder:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Foreach (Shellfilesystemfolder folder In Shelllibrary)
5 {
6 Debug. writeline (Folder. Path );
7 }
8 }
Change the default storage location:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. defaultsavefolder = Newsavelocation;
5 }
Change library icon:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. iconresourceid = New Iconreference (modulename, resourceid );
5 }
Lock library Navigation Pane:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. ispinnedtonavigationpane = True ;
5 }
Set the library type:
1 Using (Shelllibrary =
2 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
3 {
4 Shelllibrary. librarytype = Librarytype;
5
6 // Librarytype can be:
7 // Libraryfoldertype. Generic
8 // Libraryfoldertype. Documents
9 // Libraryfoldertype. Music
10 // Libraryfoldertype. Pictures
11 // Libraryfoldertype. Videos
12 }
Open the library management interface:
1 Shelllibrary. showmanagelibraryui (
2 Libraryname, folderpath, hownerwnd, title, instruction, allownonindexablelocations );
Delete database:
1 String Fileextension = " . Library-MS " ;
2
3 File. Delete (path. Combine (folderpath, libraryname + Fileextension ));
Notification of database changes:
1 String Fileextension = " . Library-MS " ;
2
3 Filesystemwatcher librarywatcher = New Filesystemwatcher (folderpath );
4 Librarywatcher. policyfilter = Policyfilters. lastwrite;
5 Librarywatcher. Filter = Libraryname + Fileextension;
6 Librarywatcher. includesubdirectories = False ;
7
8 Librarywatcher. Changed + = (S, E) =>
9 {
10 // Cross thread call
11 This . Dispatcher. Invoke ( New Action (() =>
12 {
13 Using (Shelllibrary =
14 Shelllibrary. Load (libraryname, folderpath, isreadonly ))
15 {
16 // Get changed information
17 ...
18 }
19 }));
20 };
21 Librarywatcher. enableraisingevents = True ;
Original article: http://blogs.microsoft.co.il/blogs/arik/archive/2010/03/15/windows-7-libraries-c-quick-reference.aspx