Write a string to a file in vb.net

July 15, 2010 - 15:15

Writing to a file works very similarly to when reading a file. The filestream is created passing the details of the filename and type of access.

<%@Import Namespace="System.IO" %>

Dim Document as string = "this is a test"

Dim myfilestream as new _
System.io.Filestream("test.txt", _
system.io.filemode.create, _
system.io.fileaccess.write, _

dim mywriter as new system.io.streamwriter(myfilestream)

Remember to close the file at the end, otherwise you will have problems accessing the file unless IIS is restarted.

© 2011 simplevb.net