Saturday, 3 February 2007

FileInfo Class

The FileInfo class provides instance methods for the creation, copying, deletion, moving and opening of files, and aids in the creation of FileStream objects. The FileInfo class is a sealed class meaning you are unable to inherit from it.

Many of the FileInfo methods return other I/O types when you create or open files. You can use these other types to further manipulate a file.

If you are going to reuse an object several times, you should consider using the instance method of FileInfo instead of the corresponding static methods of the File class, because a security check will not always be necessary.

Common Members
  • FileInfo (Initialises a new instance of the FileInfo class, which acts a wrapper for a file path).
  • Attributes (Gets/Sets the FileAttributes of the current FileSystemInfo).
  • CreationTime (Gets/Sets the creation time of the current FileSystemInfo object).
  • Directory (Gets an instance of the parent directory).
  • DirectoryName (Gets a string representing the directories full path).
  • Exists (Gets a value indicating whether a file exists).
  • Extension (Gets the string representing the extension part of the file).

Common Methods

  • AppendText (Creates a StreamWriter that appends text to the file represented by this instance of the FileInfo).
  • CopyTo (Copies an existing file to a new file).
  • Create (Creates a file).
  • CreateText (Creates a StreamWriter that writes a new text file).
  • Decrypt (Decrypts a file that was encrypted by the current account using the Encrypt method).
  • Delete (Permanently deletes a file).
  • Encrypt (Encrypts a file so that only the account used to encrypt the file can decrypt it).
  • MoveTo (Moves a specified file to a new location, providing the option to specify a new file name).
  • Open (Opens a file with various read/write and sharing privileges).
  • OpenRead (Create a read-only FileStream).
  • OpenText (Creates a StreamReader with UTF8 encoding that reads from an existing text file).
  • OpenWrite (Creates a write-only FileStream).
  • Refresh (Refreshes the state of the object).
  • Replace (Replaces the contents of a specified file with the file described by the current FileInfo object, deleting the original file, and creating a backup of the replaced file).

No comments: