O
-OSD-
Guest
Hi,
I am trying to create a file and write data into it using the following code but it seems like my is being created but no data is written into the file. If someone has another approach to achieve the same, please share your thoughts:
Imports System.Management
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not IO.File.Exists("C:\test.ps1") Then
'Create the file
Dim file As System.IO.FileStream
file = System.IO.File.Create("c:\test.ps1")
file.Close()
Dim addInfo As New System.IO.StreamWriter("c:\test.ps1")
addInfo.WriteLine("first line of text")
addInfo.WriteLine("") ' blank line of text
addInfo.WriteLine("3rd line of some text")
addInfo.WriteLine("4th line of some text")
addInfo.WriteLine("5th line of some text")
Else 'Proceed with other options
'Command here
End If
End Sub
End Class
Continue reading...
I am trying to create a file and write data into it using the following code but it seems like my is being created but no data is written into the file. If someone has another approach to achieve the same, please share your thoughts:
Imports System.Management
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Not IO.File.Exists("C:\test.ps1") Then
'Create the file
Dim file As System.IO.FileStream
file = System.IO.File.Create("c:\test.ps1")
file.Close()
Dim addInfo As New System.IO.StreamWriter("c:\test.ps1")
addInfo.WriteLine("first line of text")
addInfo.WriteLine("") ' blank line of text
addInfo.WriteLine("3rd line of some text")
addInfo.WriteLine("4th line of some text")
addInfo.WriteLine("5th line of some text")
Else 'Proceed with other options
'Command here
End If
End Sub
End Class
Continue reading...