03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

834 ❘ Appendix S Filesystem Classes<br />

Shell32.Shell<br />

Shell32.Shell is an interface for working with the Windows shell. It enables you to interact with<br />

virtual objects representing such things as the recycle bin.<br />

To use Shell32.Shell, first add a reference to “Microsoft Shell Controls And Automation” on<br />

the <strong>Reference</strong> Manager’s COM tab. To make using the Shell class easier, add the following using<br />

directive to the program.<br />

using Shell32;<br />

Now you can use code similar to the following to enumerate the files in the recycle bin.<br />

const int RECYCLE_BIN_NAMESPACE = 10;<br />

Shell shell = new Shell();<br />

Folder bin = shell.NameSpace(RECYCLE_BIN_NAMESPACE);<br />

// List the files.<br />

foreach (FolderItem item in bin.Items())<br />

{<br />

Console.WriteLine(item.Name + "\n<br />

}<br />

" + item.Path);<br />

This code creates a new Shell object and uses that object’s NameSpace method to get a Folder<br />

object representing the recycle bin. It then loops through the items returned by the Folder’s Items<br />

method, displaying each item’s name and path.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!