I have this function:
private void button6_Click(object sender, EventArgs e)
{
crawlLocaly1 = new CrawlLocaly();
crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
DialogResult dr = crawlLocaly1.ShowDialog(this);
if (dr == DialogResult.Cancel)
{
crawlLocaly1.Close();
}
else if (dr == DialogResult.OK)
{
//LocalyKeyWords.Add(crawlLocaly1.getText() + "," + mainUrl);
if(LocalyKeyWords.ContainsKey(mainUrl))
{
LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
}
else
{
LocalyKeyWords.Add(mainUrl, new List<string>(new string[]
{
crawlLocaly1.getText()
}
));
}
crawlLocaly1.Close();
}
}
When the user type something to textBox and click ok so the result in the LocalKeyWords which is Dictionary> is like:
In index 0 there will be for example: http://www.google.com","google
Where google is the key that belong to the http://www.google.com
Now if the user enter a keyword once to the url it will go to the second part and if the user change the key for the same url it will go to the first part else if the user changed the url so it will go to the second part.
First time it's putting a key for the url second its updating the key for the same url or put a new key for a new url.
So the List should be like this:
index 0 http://www.google.com,google
index 1 http://www.microsoft.com,com
And so on...
And this function is working correctly I just need to add the List to a text file on the hard disk.
So in the Form1 level I have streamwriter w = new streamwriter(@"d: est.txt");
In fact when I'm using a breakpoint on the List I see on the left the url then , and then I see something else not the keyword:
[0] = {[http://www.google.co.il, System.Collections.Generic.List`1[System.String]]}
Its not a bug or something it's just on a breakpoint that's how I see it. Instead System.Collections.Generic.List`1[System.String] I was suppose to see the keyword for example: google
Any way how do I write the List values to the text file so the text file format will be like this:
0 http://www.google.com,google
1 http://www.microsoft.com,hello
2 http://www.cnet.com,Daniel
0 1 2 present the indexs and url's present the mainUrl and the right sie present the Keys(keywords the user entered).
And then how do I read back the values from the text file to the lixtBox ?
So when I'm running the program in the constructor it will read the text file and show me in a listBox this format:
url: http://www.google.com --- keword: google
url: http://www.microsoft.com --- keword: hello
url: http://www.cnet.com --- keword: Daniel
So in the listBox the user will see it nicer then in the text file.
See Question&Answers more detail:
os