UPGRADE: MCAD Skills to MCPD Web Developer by Using the Microsoft .NET Framework
UPGRADE: MCAD Skills to MCPD Windows Developer by Using the Microsoft .NET Framework
UPGRADE: MCSD Microsoft .NET Skills to MCPD Enterprise Application Developer by Using the Microsoft .NET Framework: Part 1
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
File class - Static class used for moving/renaming files. They've added quite a few methods for convience and better exposed the feature set of NTFS. Look at AppendAllText, Decrypt, Encrypt, GetAccessControl, ReadAllBytes, ReadAllLines, ReadAllText, Replace, SetAccessControl, WriteAllBytes, WriteAllLines, WriteAllText
FileInfo class - Each instance of this class represents a file. Members are similiar to the File class. Doesn't have some of the convenience methods like ReadAllText, WriteAllText...
Directory class - Static class used to manipulate file directories. Doesn't appear to have changed except GetAccessControl and SetAccessControl methods have been added.
DirectoryInfo class - Each instance of this class represents a directory. Members are similiar to the File class. Also has GetAccessControl and SetAccessControl methods.
DriveInfo class - New class that allows you to query to see what drives (logical) are attached to a system. Each instance represents a drive. You can get the capacity, volume label, free space, and the type of drive.
DriveType enum - enum that specifies the type of drive represented by the DriveInfo class. CDROM, Fixed, Network, RAM, Removeable (USB or floppy), unknown. There is also a NoRootDirectory member. I don't know what that is for. The enum is not decorated with the FlagsAttribute, so a DriveType can't be Fixed AND NoRootDirectory.
FileSystemInfo class - base class for both FileInfo and DirectoryInfo
FileSystemWatcher class - I hate this component. I used it in an project and kept missing files because the buffer would overflow and the error event wasn't consistently raised. Read the class description and understand the limitations of the component. It doesn't look like it has been changed(meaning new methods and properties).
Path class - Allows you do deal with filename strings in a controlled fashion. If you want to change the extension, call the ChangeExtension method, rather than doing the string parsing yourself. Has some interesting members that I didn't know about, such as GetTempFilename. There is a new method called GetRandomFilename. It returns a random temp filename, but doesn't create it. GetInvalidFileNameChars and GetInvalidPathChars are also new.
ErrorEventArgs - object that is supplied to the error event in the FileSystemWatcher when something goes wrong. GetException returns the exception object for the error. Like I said, I had problems with the FileSystemWatcher. Know it for the test, but don't use it in a real project.
RenamedEventArgs - object that is supplied to the rename event in the FileSystemWatcher. Has OldFullPath and OldName properties. Derived from FileSystemEventArgs
Next up - System.IO.Compression