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.

434 ❘ CHAPTER 19 File System Objects<br />

(continued)<br />

Property or Method<br />

MoveTo<br />

Name<br />

Open<br />

OpenRead<br />

OpenText<br />

OpenWrite<br />

Refresh<br />

Replace<br />

ToString<br />

Purpose<br />

Moves the file to a new location. If the destination uses a relative path,<br />

it is relative to the application’s current directory, not to the FileInfo<br />

object’s directory. When this method finishes, the FileInfo object is<br />

updated to refer to the file’s new location.<br />

The file’s name without the path information.<br />

Opens the file with various mode (Append, Create, CreateNew, Open,<br />

OpenOrCreate, or Truncate), access (Read, Write, or ReadWrite),<br />

and sharing (Read, Write, ReadWrite, or None) settings. This method<br />

returns a FileStream object attached to the file.<br />

Returns a read-only FileStream attached to the file.<br />

Returns a StreamReader with UTF-8 encoding attached to the file<br />

for reading.<br />

Returns a write-only FileStream attached to the file.<br />

Refreshes the FileInfo object’s data.<br />

Takes three file paths as parameters, representing a source file,<br />

a destination file, and a backup file. If the backup file exists, this<br />

method permanently deletes it. It then moves the destination file to<br />

the backup file, and moves the source file to the destination file.<br />

Returns the file’s fully qualified name.<br />

FileSystemWatcher<br />

The FileSystemWatcher class keeps an eye on part of the file system and raises events to let your<br />

program know if something changes. For example, a FileSystemWatcher can monitor a directory<br />

and raise an event when a new file appears so your program can process the file.<br />

The FileSystemWatcher class’s constructor takes parameters that tell it which directory to watch<br />

and that give it a filter for selecting files to watch. For example, the filter *.txt makes it watch for<br />

changes to text files. The default filter is *.*, which catches changes to all files that have extensions.<br />

The following table describes the FileSystemWatcher class’s most useful properties.<br />

Property<br />

EnableRaisingEvents<br />

Purpose<br />

Determines whether the watcher is enabled. (This property is<br />

false by default, so the watcher does not raise any events until<br />

you set it to true.)<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!