School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,213 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,543 people online right now. Registration is fast and FREE... Join Now!




Adding A History To Your Browser

 
Reply to this topicStart new topic

> Adding A History To Your Browser, Working with a browsing history in VB.NET

Magic_Man
Group Icon



post 2 Apr, 2009 - 04:42 PM
Post #1


There are some great browser tutorials here but something I haven't seen in any of them is how to add a way to save the user's history. I had to figure the process out myself and it was a nightmare but fortunately, I've decided to share my knowledge with my fellow beginners. This is my first tutorial so please forgive me if it's not perfect.

First, you'll need a browser. If you haven't made one, try http://www.dreamincode.net/forums/showtopic45487.htm for a nice walkthrough.

The first thing to do is to add a setting where you can save the history after the program closes. To do this, click Project, and then (Your App Name) Properties. Locate the Settings tab. For our example, we'll name it History. Our type will be System.Collections.Specialized.StringCollection. Leave the Scope set to User and we will set the value with our code.

Attached Image

Next, we'll need to add some code that will save the browsed pages to My.Settings.History. To do this, we add a line in the codeblock for the Browser_Navigated event.

CODE
Private Sub Browser_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles Browser.Navigated
    
        My.Settings.History.Add(Browser.Url.ToString)

    End Sub


Now that our browser can save its history, we need to give it a way to load the existing history. I used a seperate form for the history with a listbox docked within it as it's a very simple way to manage the collection.

CODE
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            ListBox1.DataSource = My.Settings.History

    End Sub


The last thing we need for our history is a way to browse to an item when it's clicked.

CODE
Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click

        Main.Browser.Navigate(ListBox1.SelectedItem)

    End Sub


You can also add a button with the following code to empty the history.

CODE
My.Settings.History.Clear()


I hope this will be helpful to anyone with the same problem I had.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

nritzau
Group Icon



post 2 Jun, 2009 - 03:19 AM
Post #2
QUOTE(Magic_Man @ 2 Apr, 2009 - 04:42 PM) *

There are some great browser tutorials here but something I haven't seen in any of them is how to add a way to save the user's history. I had to figure the process out myself and it was a nightmare but fortunately, I've decided to share my knowledge with my fellow beginners. This is my first tutorial so please forgive me if it's not perfect.

First, you'll need a browser. If you haven't made one, try http://www.dreamincode.net/forums/showtopic45487.htm for a nice walkthrough.

The first thing to do is to add a setting where you can save the history after the program closes. To do this, click Project, and then (Your App Name) Properties. Locate the Settings tab. For our example, we'll name it History. Our type will be System.Collections.Specialized.StringCollection. Leave the Scope set to User and we will set the value with our code.

Attached Image

Next, we'll need to add some code that will save the browsed pages to My.Settings.History. To do this, we add a line in the codeblock for the Browser_Navigated event.

CODE
Private Sub Browser_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles Browser.Navigated
    
        My.Settings.History.Add(Browser.Url.ToString)

    End Sub


Now that our browser can save its history, we need to give it a way to load the existing history. I used a seperate form for the history with a listbox docked within it as it's a very simple way to manage the collection.

CODE
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            ListBox1.DataSource = My.Settings.History

    End Sub


The last thing we need for our history is a way to browse to an item when it's clicked.

CODE
Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click

        Main.Browser.Navigate(ListBox1.SelectedItem)

    End Sub


You can also add a button with the following code to empty the history.

CODE
My.Settings.History.Clear()


I hope this will be helpful to anyone with the same problem I had.


Thanks for that tutorial that was precise and simple really good job. It helped me happy.gif.
Go to the top of the page
+Quote Post

VB.Terry
Group Icon



post 1 Sep, 2009 - 10:52 AM
Post #3
This is the best tut for making a history in a web browser i've ever seen thanks dude
Go to the top of the page
+Quote Post

MysteriousFeez
*



post 21 Sep, 2009 - 02:25 PM
Post #4
Thanks i never thought of doing this but before i just had my history go to a folder path that shows all you history for all your webbrowsers. But the only bad thing is, you cant do this for tabbed webbrowsers which use the CType thing.

This post has been edited by MysteriousFeez: 21 Sep, 2009 - 02:38 PM
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 09:55PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month