DotNetWebTutor.com                                                    Link to Us

My.Computer.FileSystem
New with .net 2.0

Reading from a file:
label1.Text = My.Computer.FileSystem.ReadAllText("Myfile.txt")

Saving a file
My.Computer.FileSystem.WriteAllText(“Myfile.txt”,textbox1.text, true)

Without a path it saves the file in the same directory are the application.
myfile.txt
In this case the bin/debug folder of my project
stream from the web
Stream from a network

  • Streams can be more than files
  • Create a new project
  • Add a button and a textbox
  • Set the textbox to multiline and the scrollbars to Both
  • Add this code to the top of the page:

Imports System.IO
Imports system.net

  • Add this code to the button click event:

Dim myRequest As WebRequest
myRequest = WebRequest.Create("http://www.starkstate.edu")
Dim theResponse As WebResponse = myRequest.GetResponse()
Dim responseStream As Stream = theResponse.GetResponseStream()
Dim reader As New StreamReader(responseStream)

The Stringbuilder class provides a more efficient way to concatenate strings. Adding one string to another actually causes a new string to be created.
Add this code to the top of the page:
Imports System.Text

Add this code below your previous code in the button click event:

 

Dim sb As New StringBuilder
Do
sb.Append(reader.ReadLine)
sb.Append(vbCrLf)
Loop While Not reader.ReadLine Is Nothing
TextBox2.Text = sb.ToString()

stream from a network