Cool site to make money from PTC ,PTU and PTS sites and adfly,adf.ly,youtube,facebool,twitter,neobux,probux and blogging tips, tools, tutorials many things.

How to access Internet Explorer History in C#

by OTHMAN OMER OTHMAN ALAMODI , at 6:54 AM , have 0 comments
So, you want to know how to access history for various browsers in C#? I found it very difficult to get it working correctly, so here is my top choices for Chrome, Firefox, and IE history code. Internet ExplorerFirst off, here is IE. IE is, I think, the easiest history to be obtained. Browser history for IE is stored in the registry key of HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs. Now, Microsoft has published an interface on IUrlHistory, however that was not a C# wrapper. So, an article on CodeProject has a UrlHistoryLibrary.dll file which allows access to read and modify IE history.  The article shows how to to use the whole interface, however here is some prewritten code for returning IE history:
public class IE
{
public IEnumerable<URL> GetHistory()
{

UrlHistoryWrapperClass urlHistory;
UrlHistoryWrapperClass.STATURLEnumerator enumerator;
List<STATURL> list = new List<STATURL>();

urlHistory = new UrlHistoryWrapperClass();
enumerator = urlHistory.GetEnumerator();
enumerator.GetUrlHistory(list);

List<URL> URLs = new List<URL>();

foreach (STATURL url in list)
{
string browser = "-- Internet Explorer";

bool containsBoth = url.URL.Contains("file:///");

if (url.Title != "" && containsBoth == false){
Console.WriteLine(String.Format("{0} {1} {2}", url.Title, url.URL, browser));
Thread.Sleep(500);
}

}
return URLs;
}
}
Here is the URL class:
public class URL
{
string url;
string title;
string browser;
public URL(string url, string title, string browser)
{
this.url = url;
this.title = title;
this.browser = browser;
}
}
 Here is how you use this code:
  1. Go to the Codeproject page, and download the demo project. You may have to sign up for a free account. Now, open up the "UrlHistoryLibrary" project in Visual Studio and then build it. You should now have a "UrlHistoryLibrary.dll" file in /bin/debug.
  2. Now, create a new console project in Visual Studio. I use the 2010 Pro version.
  3. Right click the "References" folder, in the Solution Explorer, and choose the option to "Add Reference". Now, select the "Browse" folder and navigate into your "UrlHistoryLibrary/Bin/Debug" folder and select "UrlHistoryLibrary.dll". 
  4. Now, in your references, add 
    using UrlHistoryLibrary;
    using System.Diagnostics;
    using System.Threading;
  5. Now, add the above IE class to your code. Right under that, outside of the IE class, add the URL class.  
  6. Add a main class, or public static void Main(string[] args). Inside of that, include the following:
    Process[] process_IE = Process.GetProcessesByName("iexplore");

    if (process_IE.Length == 0)
    {
    IE ie = new IE();

    ie.GetHistory();
    }
    else
    Console.WriteLine("Sorry, IE is open. Please close IE and try again.");
  7. Now, when you run your console program, you should get a list of History visited, in the format of Title, Url, Broswer.
A few notes:
  • I have modified this a bit from the original code. I have made it so that the results will not display results with "file:///" in the url. It will also not display any empty titles.
  • In the main function, I have added a check that will tell you if you have IE open, when you try to run. If so, it will give you an error message.
  • I have added a 5 second delay between each URL.
Here is the complete tested source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using UrlHistoryLibrary;


namespace BlogTestIE
{
class Program
{
static void Main(string[] args)
{
Process[] process_IE = Process.GetProcessesByName("iexplore");

if (process_IE.Length == 0)
{
IE ie = new IE();

ie.GetHistory();
}
else
Console.WriteLine("Sorry, IE is open. Please close IE and try again.");

}
}

public class IE
{
public IEnumerable GetHistory()
{

UrlHistoryWrapperClass urlHistory;
UrlHistoryWrapperClass.STATURLEnumerator enumerator;
List list = new List();

urlHistory = new UrlHistoryWrapperClass();
enumerator = urlHistory.GetEnumerator();
enumerator.GetUrlHistory(list);

List URLs = new List();

foreach (STATURL url in list)
{
string browser = "-- Internet Explorer";

bool containsBoth = url.URL.Contains("file:///");

if (url.Title != "" && containsBoth == false)
{
Console.WriteLine(String.Format("{0} {1} {2}", url.Title, url.URL, browser));
Thread.Sleep(500);
}

}
return URLs;
}
}

public class URL
{
string url;
string title;
string browser;
public URL(string url, string title, string browser)
{
this.url = url;
this.title = title;
this.browser = browser;
}
}
}
OTHMAN OMER OTHMAN ALAMODI
How to access Internet Explorer History in C# - written by OTHMAN OMER OTHMAN ALAMODI , published at 6:54 AM, categorized as .Net , C# , Visual Studio . And have 0 comments
No comment Add a comment
Cancel Reply
GetID
Theme designed by Damzaky - Published by Proyek-Template
Powered by Blogger