Dim ANSIString() As Byte, MyEncoder As New System.Text.ASCIIEncoding()
Dim fFile As IO.File, fStream As IO.FileStream
' Set the source string and filename
Dim sSourceString As String = "Hello, World! This is a test!"
Dim sFilename As String = "C:\test.txt"
' Store the ANSI encoded string in ANSIString
ANSIString = MyEncoder.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.ASCII, MyEncoder.GetBytes(sSourceString))
Try
' Delete the file if it already exists
If fFile.Exists(sFilename) Then
fFile.SetAttributes(sFilename, IO.FileAttributes.Normal)
fFile.Delete(sFilename)
End If
Catch myException As Exception
' Show a message box if an error occurs
MessageBox.Show(myException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try