Tag Archives: IO

Write Text to a Text File with Stream Writer Class using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)
 

This will use the Stream Writer class under the System.IO namespace to write text to a textfile.

        '
        'Write to text file with the Stream Writer Class
        Dim sWriter As IO.StreamWriter = New IO.StreamWriter("c:\newTextFile.txt")

        'This is pretty much easy to understand. No explanation 
        sWriter.WriteLine("Hi")

        sWriter.WriteLine("Testing out this code")

        sWriter.WriteLine("Hopefully this code will work")

        sWriter.WriteLine("Lets flush the stream and see")

        'Flush all data to the file.   
        sWriter.Flush()

        sWriter.Close()

How to Check if a File and Directory or Folder Exists using VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.00 out of 5)
 

This shows how to check if a File or a Directory and Folder Exists using VB.NET and Higher

This will check if a File exists or not


        MessageBox.Show(IO.File.Exists("d:\someFileName.txt"))

This will check if a Folder or Directory exists or not


        MessageBox.Show(IO.Directory.Exists("c:\myFolder"))