Advertisement
Guest User

RECORDING HISTORY AND BOOKMARK

a guest
Jan 25th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Net;
  4. using System.Runtime.Serialization;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Xml.Serialization;
  7.  
  8. public class WebUrl
  9. {
  10. private string url;
  11. public string urlink
  12. {
  13. get { return url; }
  14. set { url = value; }
  15. }
  16. }
  17.  
  18. //mao ni event niya to automatically record history
  19. private void geckoWebBrowser1_Navigated(object sender, Skybound.Gecko.GeckoNavigatedEventArgs e)
  20. {
  21. WebUrl url = new WebUrl();
  22. url.urlink = geckoWebBrowser1.Url.ToString();
  23. AppendData(url, Path.GetDirectoryName(Application.ExecutablePath) + "history.bin"); //auto create na ni sya
  24. }
  25.  
  26. //event to record bookmark
  27. private void btnSaveBookmark_Click(object sender, EventArgs e)
  28. {
  29. WebUrl url = new WebUrl();
  30. url.urlink = geckoWebBrowser1.Url.ToString();
  31. AppendData(url, Path.GetDirectoryName(Application.ExecutablePath) + "bookmark.bin"); //auto create na ni sya
  32. }
  33.  
  34. public void AppendData(WebUrl url, string filename)
  35. {
  36. XmlSerializer xmlser = new XmlSerializer(typeof(List<WebUrl>));
  37. List<WebUrl> list = null;
  38. try
  39. {
  40. using (Stream s = File.OpenRead(filename))
  41. {
  42. list = xmlser.Deserialize(s) as List<WebUrl>;
  43. }
  44. }
  45. catch
  46. {
  47. list = new List<WebUrl>();
  48. }
  49. list.Add(url);
  50. using (Stream s = File.OpenWrite(filename))
  51. {
  52. xmlser.Serialize(s, list);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement