473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

To save or not to save

Hi, ive just finished building more "tabbed web browser with favourites menu" but i cant ge the favourites menu to work properly. THe add functions are ok the problem is I cant ge t the favourites to save / load.

Expand|Select|Wrap|Line Numbers
  1.  #region Using directives 
  2.  
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using System.Security.Policy;
  11. using System.Text;
  12. using System.Xml;
  13. using System.Xml.Serialization;
  14. using System.IO;
  15.  
  16. #endregion
  17.  
  18. namespace MyOwnTabbedBrowser
  19. {
  20. public partial class BrowserExplorer : Form
  21. {
  22. int current_tab_count = 0;
  23.  
  24. private string theURL = String.Empty;
  25.  
  26. ArrayList tabpages = new ArrayList();
  27.  
  28. ArrayList webpages = new ArrayList();
  29.  
  30. private Favourite theFavourites = new Favourite();
  31.  
  32. public BrowserExplorer()
  33. {
  34. InitializeComponent();
  35. tabControl1.TabPages.Clear();
  36. Create_a_new_tab();
  37. WebBrowser webpage = GetCurrentWebBrowser();
  38. webpage.GoHome();
  39. WebBrowser thiswebpage = GetCurrentWebBrowser();
  40. }
  41.  
  42. public string TheURL
  43. {
  44. get
  45. {
  46. return comboBoxurl.Text;
  47. }
  48. set
  49. {
  50. this.theURL = value;
  51. }
  52.  
  53. }
  54.  
  55. private void BrowserExplorer_FormClosing(object sender, FormClosingEventArgs e)
  56. {
  57. this.theFavourites.DoSaveFavourites();
  58. }
  59.  
  60. public void BrowserExplorer_Load(object sender, EventArgs e)
  61. {
  62. this.tsBack.Enabled = false;
  63. this.tsbForward.Enabled = false;
  64. this.theFavourites = Favourite.DoLoadFavourites();
  65. foreach (Favourite currentItem in this.theFavourites.TheFavouritesCollection)
  66. {
  67. this.theFavouriteMenuToolStripItem.DropDown.Items.Add(currentItem.TheDisplayName);
  68. this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].ToolTipText = currentItem.TheURL;
  69. }
  70. }
  71.  
  72.  
  73. private void addNewFavouriteToolStripMenuItem_Click(object sender, EventArgs e)
  74. {
  75. WebBrowser thiswebpage = GetCurrentWebBrowser();
  76.  
  77. MessageBox.Show("About to add favourite, change the displaname and theUrl in code:");
  78. Favourite theNewFavourite = new Favourite((thiswebpage.Document.Title), (TheURL));
  79.  
  80. theNewFavourite.DoAddFavourite(theNewFavourite);
  81.  
  82. this.theFavouriteMenuToolStripItem.DropDown.Items.Add(theURL);
  83.  
  84. this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].ToolTipText = theNewFavourite.TheURL;
  85. this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].Text = theNewFavourite.TheDisplayName;
  86. this.theFavouriteMenuToolStripItem.DropDown.ItemClicked += new ToolStripItemClickedEventHandler(DropDown_ItemClicked);
  87. }
  88.  
  89. void DropDown_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  90. {
  91. WebBrowser thiswebpage = GetCurrentWebBrowser();
  92. thiswebpage.Navigate(e.ClickedItem.ToolTipText);
  93. }
  94.  
  95. private void theFavouriteMenuToolStripItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
  96. {
  97. WebBrowser thiswebpage = GetCurrentWebBrowser();
  98.  
  99. //thiswebpage.Navigate(TheURL);
  100. }
  101.  
  102.  
  103.  
  104.  
  105.  
  106. public class Favourite
  107. {
  108. //****************** String Declaration **********************//
  109. private string theDisplayName = string.Empty;
  110. private string theURL = string.Empty;
  111. private List<Favourite> theFavourites = new List<Favourite>();
  112.  
  113. //****************** String Definition ***********************//
  114.  
  115. public List<Favourite> TheFavouritesCollection
  116. {
  117. get
  118. {
  119. return this.theFavourites;
  120. }
  121. }
  122.  
  123. public string TheDisplayName
  124. {
  125. get
  126. {
  127. return theDisplayName;
  128. }
  129. set
  130. {
  131. theDisplayName = value;
  132. }
  133. }
  134.  
  135. public string TheURL
  136. {
  137. get
  138. {
  139. return this.theURL;
  140. }
  141. set
  142. {
  143. this.theURL = value;
  144. }
  145.  
  146. }
  147.  
  148. public Favourite() { }
  149.  
  150. public Favourite(string displayName, string url)
  151. {
  152. theDisplayName = displayName;
  153. theURL = url;
  154. }
  155.  
  156. public int CompareTo(Favourite fav)
  157. {
  158. return TheDisplayName.CompareTo(TheDisplayName);
  159. }
  160. //**************Favourite Add/Load/Save Functions ****************//
  161. public void DoAddFavourite(Favourite theFavToAdd)
  162. {
  163. this.theFavourites.Add(theFavToAdd);
  164. }
  165. public static Favourite DoLoadFavourites()
  166. {
  167. if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\favourites.xml"))
  168. {
  169. //deserialize Type[] theTypes = new Type[1];
  170. Type[] theTypes = new Type[1];
  171. theTypes[0] = typeof(List<Favourite>);
  172. XmlSerializer theSerializer = new XmlSerializer(typeof(Favourite), theTypes);
  173. System.IO.StreamReader theReader = new System.IO.StreamReader(System.Windows.Forms.Application.StartupPath + "\\favourites.xml");
  174. Favourite theFavourites = (Favourite)theSerializer.Deserialize(theReader);
  175. theReader.Close();
  176. return theFavourites;
  177. }
  178. else
  179. {
  180. return new Favourite();
  181. }
  182. }
  183. public void DoSaveFavourites()
  184. {
  185. //serialize Type[] theTypes = new Type[1];
  186. Type[] theTypes = new Type[1];
  187. theTypes[0] = typeof(List<Favourite>);
  188. XmlSerializer theSerializer = new XmlSerializer(typeof(Favourite), theTypes);
  189. System.IO.StreamWriter theWriter = new System.IO.StreamWriter(System.Windows.Forms.Application.StartupPath + "\\favourites.xml");
  190. theSerializer.Serialize(theWriter, this);
  191. theWriter.Close();
  192. }
  193.  
  194. internal void Add(Favourite theFavToAdd)
  195. {
  196. throw new Exception("The method or operation is not implemented.");
  197. }
  198. }
  199. }
  200.  
PLEASE HELP ME!!!!!!!!!
Oct 21 '06 #1
0 1374

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: F. Hall | last post by:
If I read a bitmap image from one file and save it to another the save operation is slow unless I draw on the image. In other words, Image inputImage = Image.FromFile( @"c:\temp\source.bmp" );...
4
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number field), the first record saves as expected, but the...
5
by: kevin | last post by:
Hi, Any help with this would be really appreciated! I'm trying to download a file from a remote server. The access permissions is okay but the problem I'm facing is that the file is getting...
2
by: Alvo von Cossel I | last post by:
hi, you can create a file with the savefiledialog. once you have done that and edit the file in the text editior that i wrote you cannot save the file, you can only create a new file or replace...
10
by: GJP | last post by:
Hello. Ive been asked to make my own notepade for college assignment. All ig going well, but i cant get the save to work. I can get Save a (shows dialog box), i can get it to just save too,...
5
by: C Watson | last post by:
Hi, I'm wondering if anyone can help me with AJAX in ASP.NET 1.1. I have a very specific feature that I would like to use it for. I have a rather long form that the users use to enter data...
3
by: =?Utf-8?B?YXNkZg==?= | last post by:
Hello. I am making a web application with c# and am using this code: Response.ContentType = "application/x-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" +...
0
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
0
by: ppardi | last post by:
I'm developing an addin for Word 2007 and I need to determine whether a user saves a Word 2007 document in an older format (97-2003) after a save as is done. The scenario is that the user starts...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.