Solved

URL navigation - limited length in VB.net!!

Posted on 2006-06-09
26
382 Views
Last Modified: 2010-04-23
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.
0
Comment
Question by:chrismalone
  • 10
  • 10
  • +1
26 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 16873284
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16879857
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
 
LVL 1

Author Comment

by:chrismalone
ID: 16879911
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16879912
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
 
LVL 1

Author Comment

by:chrismalone
ID: 16879919
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
 
LVL 1

Author Comment

by:chrismalone
ID: 16879921
* 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
 
LVL 1

Author Comment

by:chrismalone
ID: 16879936
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
 
LVL 1

Author Comment

by:chrismalone
ID: 16879938
* 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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16879998
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16880477
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16880483
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:chrismalone
ID: 16881809
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 16883582
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
 
LVL 1

Author Comment

by:chrismalone
ID: 17070406
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17075548
Hi again! Didnt the project I sent you work? Sorry, I thought it was ok.
0
 
LVL 1

Author Comment

by:chrismalone
ID: 17076215
sorry, it didnt get finished either.
none of those two you sent worked :(
0
 
LVL 1

Author Comment

by:chrismalone
ID: 17076227
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
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17077153
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
 
LVL 1

Author Comment

by:chrismalone
ID: 17077467
yes, that code worked great  on its own,
but wouldnt work in mine and you had to do some other project remember?
0
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17088381
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
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17118240
Closed, 250 points refunded.
Netminder
Site Admin
0
 
LVL 12

Expert Comment

by:vb_jonas
ID: 17120082
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now