Export (0) Print
Expand All
Expand Minimize

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 UTF8. Required.

StreamWriter

The following condition may cause an exception to be thrown:

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

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.")
file.Close()

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

The following permission may be necessary:

Permission Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

Community Additions

ADD
Show:
© 2015 Microsoft