Exam 70-553 - Access files and folders by using the File System classes.
Section 1
-
Part 3
-
Topic 3
-
Access files and folders by using the File System classes. (Refer System.IO namespace)
- File class and FileInfo class
- Directory class and DirectoryInfo class
- DriveInfo class and DriveType enumeration
- FileSystemInfo class and FileSystemWatcher class
- Path class
- ErrorEventArgs class and ErrorEventHandler delegate
- RenamedEventArgs class and RenamedEventHandler delegate
Summary
The File Class exposes static methods for creating, copying, moving, deleting and opening files and can create filestream objects while the FileInfo class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.
The Directory Class exposes static methods for creating, moving and enumerating through directories while the Directory Info Class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.
The DriveInfo Class is new to .Net 2.0 and exposes information about drives like Available space, drive format, drive type, IsReady, Name, RootDirectory, TotalFreeSpace, Total Space and the volume label. The Drive Type is an enum with seven members: CDRom, Fixed, Network, NoRootDirectory, Ram, Removable and unknown.
The FileSystemInfo class is the base class that both the FileInfo and DirectoryInfo classes derive from. It can represent either a file or a directory so use this class when parsing large amounts of files or directories.
The FileSystemWatcher Class listens to file system change notifications for files or directories and raises events.
The Path Class is used to perform operations on strings that contain file and path information. By passing a string with a path in into it to some of this classes static methods you can get information like the path root, filename and extension without having to parse the string yourself.
The ErrorEventHandler delegate is the method that will handle the error event for a FileSystemWatcher Object. The ErrorEventArgs are the argurments (like the Exception itself) that will be passed into the method handling the event.
The RenamedEventHandler delegate is the method that will handle the file renamed event for a FileSystemWatcher object. The RenamedEventArgs contain the argurments (old file path, new file path) that will be passed into the method handling the event.
Other Resources & Links:
File Class
http://msdn2.microsoft.com/en-us/library/system.io.fileinfo(VS.80).aspx
FileInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.fileinfo(VS.80).aspx
Directory Class
http://msdn2.microsoft.com/en-us/library/system.io.directory(VS.80).aspx
DirectoryInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.directoryinfo(VS.80).aspx
DriveInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.driveinfo(VS.80).aspx
DriveType Enumeration
http://msdn2.microsoft.com/en-us/library/system.io.drivetype(VS.80).aspx
FileSystemInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.filesysteminfo(VS.80).aspx
FileSystemWatcher Class
http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher(VS.80).aspx
Path Class
http://msdn2.microsoft.com/en-us/library/system.io.path(VS.80).aspx
ErrorEventArgs
http://msdn2.microsoft.com/en-us/library/system.io.erroreventargs(VS.80).aspx
ErrorEventHandler Delegate
http://msdn2.microsoft.com/en-us/library/system.io.erroreventhandler(VS.80).aspx
RenamedEventArgs
http://msdn2.microsoft.com/en-us/library/system.io.renamedeventargs(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.io.renamedeventhandler(VS.80).aspx