My.Computer.FileSystem.OpenTextFileWriter Method
Opens a StreamWriter.
' Usage
Dim value As System.IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(file ,append)
Dim value As System.IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(file ,append ,encoding)
' Declaration
Public Function OpenTextFileWriter( _
ByVal file As String, _
ByVal append As Boolean _
) As System.IO.StreamWriter
' -or-
Public Function OpenTextFileWriter( _
ByVal file As String, _
ByVal append As Boolean, _
ByVal encoding As System.Text.Encoding _
) As System.IO.StreamWriter
Parameters
- file
String. File to be written to. Required.
- append
Boolean. Specifies whether to append to or overwrite information in the file. Default is False. Required.
- encoding
Encoding. Encoding to be used in writing to the file. Default is ASCII. Required.
Return Value
StreamWriter
Exceptions
The following condition may cause an exception to be thrown:
- The file name ends with a trailing slash (ArgumentException).
Tasks
The following table lists an example of a task involving the My.Computer.FileSystem.OpenTextFileWriter method.
To | See |
---|---|
Write text to a file with a StreamWriter |
How to: Write Text to Files with a StreamWriter in Visual Basic |
Example
This example opens a StreamWriter with the My.Computer.FileSystem.OpenTextFileWriter method and uses it to write a string to a text file with the WriteLine method of the StreamWriter class.
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
file.WriteLine("Here is the first string.")
Requirements
Namespace: Microsoft.VisualBasic.MyServices
Class: FileSystemProxy (provides access to FileSystem)
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
Project type | Available |
---|---|
Windows Application |
Yes |
Class Library |
Yes |
Console Application |
Yes |
Windows Control Library |
Yes |
Web Control Library |
Yes |
Windows Service |
Yes |
Web Site |
Yes |
Permissions
The following permission may be necessary:
Permission | Description |
---|---|
Controls the ability to access files and folders. Associated enumeration: Unrestricted. |
For more information, see Code Access Security and Requesting Permissions.
See Also
Tasks
How to: Write Text to Files with a StreamWriter in Visual Basic
Reference
My.Computer.FileSystem Object
System.Text.Encoding
System.IO.StreamWriter
Microsoft.VisualBasic.FileIO.FileSystem.OpenTextFileWriter