15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

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

772 ❘ ChaPTer 29 mAnipulAtinG files And the reGistry<br />

Object<br />

Class<br />

I Serializable<br />

DriveInfo<br />

Sealed Class<br />

MarshalByRefObject<br />

Abstract Class<br />

Directory<br />

Static Class<br />

File<br />

Static Class<br />

Path<br />

Static Class<br />

I Serializable<br />

FileSystemInfo<br />

Abstract Class<br />

Marshal By Ref Object<br />

DirectoryInfo<br />

Sealed Class<br />

File System Info<br />

FileInfo<br />

Sealed Class<br />

File System Info<br />

figure 29-1<br />

The following list explains the function of these classes:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

System.MarshalByRefObject — This is the base object class for .<strong>NET</strong> classes that are remotable;<br />

it permits marshaling of data between application domains. The rest of the items in this list are part<br />

of the System.IO namespace.<br />

FileSystemInfo — This is the base class that represents any fi le system object.<br />

FileInfo <strong>and</strong> File — These classes represent a fi le on the fi le system.<br />

DirectoryInfo <strong>and</strong> Directory — These classes represent a folder on the fi le system.<br />

Path — This class contains static members that you can use to manipulate pathnames.<br />

DriveInfo — This class provides properties <strong>and</strong> methods that provide information on a<br />

selected drive.<br />

In Windows, the objects that contain fi les <strong>and</strong> that are used to organize the fi le system<br />

are termed folders. For example, in the path C:\My Documents\ReadMe.txt, ReadMe<br />

.txt is a fi le <strong>and</strong> My Documents is a folder. Folder is a very Windows-specifi c term:<br />

on virtually every other operating system the term directory is used in place of folder,<br />

<strong>and</strong> in accordance with Microsoft’s goal to design .<strong>NET</strong> as a platform-independent<br />

technology, the corresponding .<strong>NET</strong> base classes are called Directory <strong>and</strong><br />

DirectoryInfo. However, due to the potential for confusion with LDAP directories<br />

(as discussed in the online Chapter 52, “Directory Services”), <strong>and</strong> because this is a<br />

Windows book, we’ll stick to the term folder in this discussion.<br />

. neT Classes That represent files <strong>and</strong> folders<br />

You will notice from the previous list that two classes are used to represent a folder <strong>and</strong> two classes are used<br />

to represent a fi le. Which one of these classes you use depends largely on how many times you need to access<br />

that folder or fi le:<br />

➤<br />

Directory <strong>and</strong> File contain only static methods <strong>and</strong> are never instantiated. You use these classes by<br />

supplying the path to the appropriate fi le system object whenever you call a member method. If you<br />

want to do only one operation on a folder or fi le, using these classes is more effi cient because it saves<br />

the overhead of instantiating a .<strong>NET</strong> class.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!