NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

FileStream.Close

Releases any resources, namely the file handle, associated with the current file stream.

[Visual Basic]
Overrides Public Sub Close()
[C#]
public override void Close();
[C++]
public: override void Close();
[JScript]
public override function Close();

Exceptions

Exception Type Condition
IOException An I/O error occurs.

Remarks

Any data previously written to the buffer is copied to the file before the file stream is closed, so it is not necessary to call Flush before invoking Close. Following a call to Close, any operations on the file stream may raise exceptions. After Close has been called once, it does nothing if called again.

The Finalize method invokes Close so that the file stream is closed before the garbage collector finalizes the object. Any objects such as a StreamWriter that may be writing to the FileStream may not have flushed their data from their internal buffers to the FileStream when FileStream's Finalize closes the Stream. To prevent data loss, it is highly recommended that you always call Close on your highest-level object.

See Also

FileStream Class | FileStream Members | System.IO Namespace