URL navigation - limited length in VB.net!!

i have this html page:
<form name=form1><input name=first_name><input name=username></form>

this vb.net code:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.WebBrowser1.Navigate(TextBox1.Text)
    End Sub
End Class


when i type in this is the 'address bar' and navigate to it, it works:

javascript:var alphaNum = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; document.form1.username.value = alphaNum.charAt(Math.floor(Math.random()*36)) + alphaNum.charAt(Math.floor(Math.random()*36)) + alphaNum.charAt(Math.floor(Math.random()*36)) + alphaNum.charAt(Math.floor(Math.random()*36)); document.form1.first_name.value = alphaNum.charAt(Math.floor(Math.random()*36)) + alphaNum.charAt(Math.floor(Math.random()*36)) + alphaNum.charAt(Math.floor(Math.random()*36));

but for some reason if i add another  + alphaNum.charAt(Math.floor(Math.random()*36))  to it (at the end before the colon), it simply does nothing.  this is actually for a much bigger project but i've created a simple new one just to try and fix the problem.
is there a limit on the length you can navigate to a url in vb.net? is there a way to overcome it?


my other problem is trying to save an image thats inside a webbrowser control.. there doesn't seem to be a function for it... ?????
if anyone can solve either of these they'll get 250 points.
thanks.
LVL 1
chrismaloneAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
NetminderConnect With a Mentor Commented:
Closed, 250 points refunded.
Netminder
Site Admin
0
 
Jens FiedererTest Developer/ValidatorCommented:
I don't know of any VB.NET limits, but I DO know that Internet Explorer has a maximum length for URLs:

http://support.microsoft.com/default.aspx?scid=KB;en-us;q208427

I am not sure what you mean with the image saving.
0
 
vb_jonasCommented:
I tried your limited length problem both in VB.Net and directly in an IE browser. Same problem, but the string length is only 513, IE should be able to handle 2083 characters according to jensfiederers link.

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
chrismaloneAuthor Commented:
well its good to know people acknowledge it.. anyone have a solution?

p.s. vb_jonas.. thats weird, as somehow i was able add another few hundred of them and it still worked in ie6.. maybe its todo with the JS virtual machine..
0
 
vb_jonasCommented:
You can set the html-objects with the webbrowser.document-property:

Me.WebBrowser1.Document.All("userName").SetAttribute("value", TextBox1.Text)

With that technique you can access the image also.
0
 
chrismaloneAuthor Commented:
how can i access the image?
it has no name or class in the html page, but i can get to it by index..
0
 
chrismaloneAuthor Commented:
* and i had to solve the problem using domdocument similar to your one above. i would have rather insert external JS but it came to that..
0
 
chrismaloneAuthor Commented:
with the image, i think its possible to emulate an alt-print-screen of the form and crop it to the image.. but i'm uncertain..
if you can answer it, you can do it here or post in this one: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21879244.html
currently the only way i can access it is: Me.WebBrowser1.Document.Images.Item(10)   and i can only use ScrollIntoView() and have the webbrowser size set to the size of the image,
to make it look like its a picturebox..  but i want to save   Me.WebBrowser1.Document.Images.Item(10)   without accessing it through a picturebox with the url in it.. since the picture in it is produced by cookies.
0
 
chrismaloneAuthor Commented:
* the other way is if i can issue a clipboard copy command on Me.WebBrowser1.Document.Images.Item(10)
by selecting it automaticlly and 'pressing' Ctrl+C automaticlly..
0
 
vb_jonasCommented:
This seems worth trying:

Once you know the actual url of each image
(make sure not to process the same image multiple times), you can download it
from the web as a stream, and then do whatever you want with it, including
saving it to a local file. The nice thing about downloading the image from the
web is that, by default, it reuses the cache of Internet Explorer and thanks to
that won't really download images twice.

A general code for downloading a
resource like an image from the web is as follows :
<PRE>
HttpWebRequest h = (HttpWebRequest) WebRequest.Create("http://weblogs.asp.net/heatherleigh/contact.aspx");
StreamReader sr = new StreamReader( h.GetResponse().GetResponseStream() );
// sr.ReadToEnd(); for instance
// or create a filewriter and store the stream there
</PRE>

http://www.codeproject.com/jscript/htmlgetshooked.asp?df=100&forumid=4684&exp=0&select=774194#xx774194xx
0
 
vb_jonasCommented:
I've made a sub that writes all images from a WebBrowser document and saves them locally, the thing is I'm not sure how it handles caching, so the images may or may not be requested once again here.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Navigate to selected path:
        Me.WebBrowser1.Navigate(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        ' Find and save images in htmlDocument
        Dim HtmlElement As HtmlElement
        Dim ImgFilename As String
        Dim ImgSrc As String
        Dim ImagesPath As String = "c:\images\"

        ' go through all images in the document
        For Each HtmlElement In WebBrowser1.Document.GetElementsByTagName("IMG")
            Dim objWReq As Net.WebRequest

            Dim objWResp As Net.WebResponse
            Dim strBuffer As String

            'Contact the website
            ImgSrc = HtmlElement.GetAttribute("src").ToString
            objWReq = Net.HttpWebRequest.Create(ImgSrc)
            ImgFilename = IO.Path.GetFileName(ImgSrc)
            objWResp = objWReq.GetResponse()

            'Hopefully we get the cached image here, so that dynamically created images wont change and the app wont have problems with authentication, have to be tested though.

            'Read the answer from the website and store it into a stream
            Dim objStream As IO.Stream
            objStream = objWResp.GetResponseStream
            Dim inBuf(100000) As Byte
            Dim bytesToRead As Integer = CInt(inBuf.Length)
            Dim bytesRead As Integer = 0
            While bytesToRead > 0
                Dim n As Integer = objStream.Read(inBuf, bytesRead, bytesToRead)
                If n = 0 Then
                    Exit While
                End If
                bytesRead += n
                bytesToRead -= n
            End While
            Dim fstr As New IO.FileStream(ImagesPath & ImgFilename, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
            fstr.Write(inBuf, 0, bytesRead)
            objStream.Close()
            fstr.Close()

            objWResp.Close()
        Next
    End Sub


0
 
chrismaloneAuthor Commented:
can you make it run without clicking a button please? you can just put in an example url and i'll change it..
i don't think it will work.. it has nocache attributes on it since its a captcha (verification image) and depends on cookies.
it would pretty much need the image already received.. if it could get it from the cache that would work .. but requesting it again probably wont (i've tried this way heaps)

and i've tried requesting the same image in a picturebox thats in the webbrowser control.. it just gets a different image and different cookies..

is there a way it can get the location of the internet cache path its currently working in? that could work maybe..
0
 
vb_jonasCommented:
Private Sub ParseForImages(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

... Paste Button2_Click-code here

End Sub


But the screen-capture way might be the best for you.  http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21879244.html
0
 
chrismaloneAuthor Commented:
i would like this and all the other related threads deleted and refunded.
vb jonas started to help me with it on msn but got side-tracked with another project and i havent seen him on msn in a while.
0
 
vb_jonasCommented:
Hi again! Didnt the project I sent you work? Sorry, I thought it was ok.
0
 
chrismaloneAuthor Commented:
sorry, it didnt get finished either.
none of those two you sent worked :(
0
 
chrismaloneAuthor Commented:
and to netminder, the reason i asked him to do it over msn was because i didnt want my source code for the public to see and use.
0
 
vb_jonasCommented:
This code is working (saving web page images) and I think it can be of use as a solution for the EE-readers:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Navigate to selected path:
        Me.WebBrowser1.Navigate(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        ' Find and save images in htmlDocument
        Dim HtmlElement As HtmlElement
        Dim ImgFilename As String
        Dim ImgSrc As String
        Dim ImagesPath As String = "c:\images\"

        ' go through all images in the document
        For Each HtmlElement In WebBrowser1.Document.GetElementsByTagName("IMG")
            Dim objWReq As Net.WebRequest

            Dim objWResp As Net.WebResponse
            Dim strBuffer As String

            'Contact the website
            ImgSrc = HtmlElement.GetAttribute("src").ToString
            objWReq = Net.HttpWebRequest.Create(ImgSrc)
            ImgFilename = IO.Path.GetFileName(ImgSrc)
            objWResp = objWReq.GetResponse()

            'Hopefully we get the cached image here, so that dynamically created images wont change and the app wont have problems with authentication, have to be tested though.

            'Read the answer from the website and store it into a stream
            Dim objStream As IO.Stream
            objStream = objWResp.GetResponseStream
            Dim inBuf(100000) As Byte
            Dim bytesToRead As Integer = CInt(inBuf.Length)
            Dim bytesRead As Integer = 0
            While bytesToRead > 0
                Dim n As Integer = objStream.Read(inBuf, bytesRead, bytesToRead)
                If n = 0 Then
                    Exit While
                End If
                bytesRead += n
                bytesToRead -= n
            End While
            Dim fstr As New IO.FileStream(ImagesPath & ImgFilename, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
            fstr.Write(inBuf, 0, bytesRead)
            objStream.Close()
            fstr.Close()

            objWResp.Close()
        Next
    End Sub
0
 
chrismaloneAuthor Commented:
yes, that code worked great  on its own,
but wouldnt work in mine and you had to do some other project remember?
0
 
vb_jonasCommented:
Yes, and I sent you the project file I got from you with my code added to your hotmail-address, but got no reply on that, so I thought it was ok.
0
 
vb_jonasCommented:
And the other question "Getting picture from webpage with VB.net" was deleted. This was something I put a lot of time into and came up with a general solution, which I really think the EE-readers can have great help with.
0
All Courses

From novice to tech pro — start learning today.