+92 332 4229 857 99ProjectIdeas@Gmail.com

How to write a file (Vb.net)


How to write a file
The namespace for writing a file is System.IO which contains built-in classes and functions to handle files with Vb.net.

Source code for writing a file
Dim fs As FileStream
fs = New FileStream("newWordFile.docx", FileMode.Create, FileAccess.Write)
Dim sr As StreamWriter
sr = New StreamWriter(fs)
sr.WriteLine("My name is saad bin saulat")
sr.Close()
First of all an object of FileStream class is declared, which is used for reading and writing operations and a file named newWordFile.docx is created for writing. After that an object of StreamWriter class is declared and an object of FileStream is passed as an argument to StreamWriter which further writes a file. At the end the StreamWriter object is closed because the file is written.


Related articles

0 comments: