open a file into treeview

hy

i have a problem with a treeview

i have a file named file:
now i want it to open the file and: when website (likewww.google.com) add the website (this is working), but i also want it to make a new root and add al later websites to that root when there is a + in the file.
Also when there i a - it must go to the top level.

i now have this code but it gave me no results

privatevoid openFavorites()

{

try

{

FileStream list =newFileStream("favorites.txt",FileMode.Open);

StreamReader reader =newStreamReader(list);

while (reader.EndOfStream ==false)

{

string line = reader.ReadLine();

if (line =="+")

{

TreeNode root1 =newTreeNode();

line = reader.ReadLine();

root1.Nodes.Add(line);

}

else

{

treeView1.Nodes.Add(line);

}

}

if (reader.EndOfStream ==true)

{

reader.Close();

list.Close();

}

}

catch

{

MessageBox.Show("error with file");

Application.Exit();

}

can anybody help me with this?

thanks in advance

[2726 byte] By [ozakiweb] at [2007-12-25]
# 1

wait il reform my question:

how do you add a root (a plus (+)) into the treeview via code?

thanks in advance

ozakiweb at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 2

Hi

Something like this:

TreeNode root = null;

TreeNode node = null;

FileStream list = new FileStream("favorites.txt", FileMode.Open);

StreamReader reader = new StreamReader(list);

while (reader.EndOfStream == false)

{

string line = reader.ReadLine();

if (line.Equals("+"))

{

root = node;

}

else

{

node = new TreeNode(line);

if (root == null)

treeView1.Nodes.Add(node);

else

root.Nodes.Add(node);

}

}

Hope this help

Markku

MarkkuBehm at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 3

hey that helped!

but its very bugious (its not your code but anyway)
its my first c# program and can someone take a look at it

it does strange things like copy the treeview 5 times (when i click a link or click the go button)

i zipped it and its 3.677 mb
link:

(yes i see its 3.59 LOL)

thanks in advance!

greets

ozakiweb at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 4

Hi

First thing what I find is place where you call 'openFaivorites' function.

Form's Activated event is't write place to call this kind of method.

At least you must clear treeview every time, but anyway it's better if you call it on form's Load event.

So I recomment that you move openFaivorites() function call from Browser_Activeted event to Browser_Load event and

add treeView clear comman to openFaivorites function.

private void openFavorites()
{
treeView1.Nodes.Clear();
....

Yours Markku

MarkkuBehm at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 5

Hi

Second thing is those 'this.update()' calls.
There isn't any reason for them.
Actually update() causes that flash effect.

And that form's Activated event handler is wrong place take 1 second brake.
I understand why it is there but mayby you should do it only ones. I mean something like this:

private bool splash = true;

private void Browser_Activated(object sender, EventArgs e)
{
if (splash)
{
splash =
false;
Thread.Sleep(1000);
splashscreen.Close();
}
}

Yours

Markku

MarkkuBehm at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 6

okay thanks!

it now does not copy the treeview.
and when i minimize and the maximze it doesnt delay!

but i have stil one problem:

i need it to only when i click a link in the favorites with www. in the string it must go tho that webpage
i tryed:

private void treeView1_MouseDoubleClick_1(object sender, MouseEventArgs e)

{

try

{

node = treeView1.SelectedNode.Text;

comp = "www.";

if (string.Equals(comp, node, StringComparison.Ordinal) != true)

{

node = "not";

}

}

catch

{

}

if (node != "not")

{

this.NavigateToUrl(node);

}

else

{ }

its also in the download

thanks in advance

ozakiweb at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...
# 7

Hi

This is one solution:

private void NavigateToUrl(string url)
{
if (url.Split('.')[0].ToLower().Equals("www") || url.Split(':')[0].ToLower().Equals("http"))
{
myBrowser.Navigate(url);
tstbUrl.Text = url;
}
}

private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
this.NavigateToUrl(e.Node.Text);
}

Yours Markku

MarkkuBehm at 2007-9-3 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...