I cant seem to find it, what is its name in .net?
Printable View
I cant seem to find it, what is its name in .net?
By Inet control, are you referring to Internet Explorer? How do you want to control it? Are you trying to have a browser window within a form? Or execute and control a seperate instance of IE?
Well, in vb6 theres a control that lets me access a webpage thru vb totally in text. It will take the source of a page and give it directly to you. It doesnt seem like theres a control to do this anymore? How would i get the text off a website into a textbox without running a webbrowser control ?
Take a look at the system.net namespace, there's webclient/request. You can probably do it with those, I've never done it though so I don't have any code for you...
well...i added the namespace but i dont know what to do now..Nothing new is on the left hand bar of my screen. Im not sure what to do now
It won't give you a GUI control, you'll need to call it in code.
Okay, gotcha now...Just i dont know which option to use
Well you could use webclient to download the file and read it...
What exactly do you want to download?
Okay, here's a quickie. This is based on a form with two textboxes, and an execute button. Textbox1 is for the url. Textbox2 is the souce of the page. Button1 gets the source and displays it in textbox2.
Before you do this, you need to set Options Explicit On, and add the following imports to your namespace:
Imports System.IO
Imports System.Net
Imports System.Text
Add the following to the button executing the code:
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim uri As New Uri(TextBox1.Text)
Dim builder As New StringBuilder
builder.Append("AbsolutePath: " & uri.AbsolutePath & ControlChars.CrLf)
builder.Append("AbsoluteUri: " & uri.AbsoluteUri & ControlChars.CrLf)
builder.Append("Host: " & uri.Host & ControlChars.CrLf)
builder.Append("HostNameType: " & uri.HostNameType.ToString() & _
ControlChars.CrLf)
builder.Append("LocalPath: " & uri.LocalPath & ControlChars.CrLf)
builder.Append("PathAndQuery: " & uri.PathAndQuery & ControlChars.CrLf)
builder.Append("Port: " & uri.Port & ControlChars.CrLf)
builder.Append("Query: " & uri.Query & ControlChars.CrLf)
builder.Append("Scheme: " & uri.Scheme)
Dim request As WebRequest = WebRequest.Create(uri)
Dim response As WebResponse = request.GetResponse()
builder = New StringBuilder
builder.Append("Request type: " & request.GetType().ToString() & _
ControlChars.CrLf)
builder.Append("Response type: " & response.GetType().ToString() & _
ControlChars.CrLf)
builder.Append("Content length: " & response.ContentLength & _
" bytes" & ControlChars.CrLf)
builder.Append("Content type: " & response.ContentType & _
ControlChars.CrLf)
MsgBox(builder.ToString())
Dim stream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(stream)
Dim data As String = reader.ReadToEnd()
reader.Close()
stream.Close()
TextBox2.Text = data
End Sub
i need code that complicated? it was just like inet1.openurl("www.google.com",icstring)
There has to be something less difficult..thx though
You just want all the html?
yeah, no parsing
ok then do this:
Code:dim wc as new net.webclient
dim MyStream as io.stream = wc.openreader("www.google.com")
dim reader as new io.streamreader(Mystream)
textbox.text = reader.readtoend
that doesnt work, gives me this error:
Could not find file 'C:\Documents and Settings\Jason\Local Settings\Application Data\Temporary Projects\WindowsApplication1\bin\Debug\www.google.com'.
and it highlights:
dim MyStream as io.stream = wc.openreader("www.google.com")
Opps sorry, you want "http:\\www.google.com"
that works a charm! Now just to understand what the heck this thing is doing..it doesnt make sense :W
Well basically a webclient allows you to connect to a URL. You then use the stream and reader to get the data and stick it in a textbox.
okay few more..
Dim MyStream As IO.Stream = ..
How come i can use io.stream, when it doesnt even show up in the intellisense menu?
edit **
also, why doesnt this work:
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim wc As New Net.WebClient Dim MyStream As IO.StreamReader = wc.OpenRead("http://google.com") 'Dim reader As New IO.StreamReader(MyStream) MessageBox.Show(MyStream.ReadToEnd) End Sub
please anyone?
io.stream doesn't show up in your intellisence? :S What if you do system.io.stream?
The reason for the streamreader is to convert the byte stream into text.
no stream doesnt come up anywhy i type it ???
ill just try and remember i guess..
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim wc As New Net.WebClient Dim MyStream As IO.Stream = wc.OpenRead("http:\\www.google.com") Dim reader As New IO.StreamReader(MyStream) MessageBox.Show(reader.ReadToEnd) End Sub
Is how it ended up, thx guys