Click here to Skip to main content
15,914,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void addTreeNode()
       {
           try
           {
               ofdInput.ShowDialog();
               StreamReader srInput = new StreamReader(ofdInput.FileName);
               tvLinks.Nodes.Clear();
               pbIcon.Image = null;

               for (int X = 1; X <= File.ReadLines(ofdInput.FileName).Count(); X++)
               {
                   try
                   {
                       MessageBox.Show(X + " / " + File.ReadLines(ofdInput.FileName).Count());
                       string URL = srInput.ReadLine();
                       Uri IconLocation = new Uri(URL);
                       string SavePath = IconLocation.Host.Replace("www.", "").Remove(IconLocation.Host.Replace("www.", "").LastIndexOf(".")) + ".ico";
                       if (!File.Exists(SavePath))
                       {
                           WebClient Client = new WebClient();
                           Client.DownloadFile("http://" + IconLocation.Host + "/favicon.ico", SavePath);
                       }
                       pbIcon.ImageLocation = SavePath;

                       if (tvLinks.Nodes.Count > 0)
                       {
                           for (int I = 0; I <= tvLinks.Nodes.Count; I++)
                           {
                               if (tvLinks.Nodes[I].Text == IconLocation.Host.ToString())
                               {
                                   tvLinks.Nodes[I].Nodes.Add(srInput.ReadLine());
                                   break;
                               }
                               else if (I == tvLinks.Nodes.Count - 1)
                               {
                                   tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
                                   break;
                               }
                           }
                       }
                       else
                       {
                           tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
                       }
                   }
                   catch
                   {
                   }
               }

           }
           catch
           {
           }
       }
Posted
Updated 30-Dec-11 3:37am
v2
Comments
Wendelius 30-Dec-11 9:37am    
What is your question exactly?
MaXx0r 30-Dec-11 9:40am    
The loading is failing, it needs to be fixed.
If I want to load 10 lines, it only loads 5 lines.
MaXx0r 30-Dec-11 16:56pm    
If this could help you, if I put this in:
1
1
2
2
3
3
then I get this out:
1
2
3

i think u problem is here
C#
if (tvLinks.Nodes[I].Text == IconLocation.Host.ToString())
    {
        tvLinks.Nodes[I].Nodes.Add(srInput.ReadLine());
        break;
    }
    else if (I == tvLinks.Nodes.Count - 1)
    {
        tvLinks.Nodes.Add(IconLocation.Host).Nodes.Add(srInput.ReadLine());
        break;
    }


You most asure that u are parsing well the info in ur text file en every
C#
tvLinks.Nodes[I].Text
a debug is recommended :P
 
Share this answer
 
Comments
MaXx0r 30-Dec-11 16:51pm    
I don't understand what you want me to change :S
darkDercane 30-Dec-11 18:09pm    
is not change anything is to check if the values returned from ur file are well obtained :P
MaXx0r 30-Dec-11 19:15pm    
The srInput.ReadLine() doesn't return me a string sometimes. In 10 lines, it returns me the first 5 lines, the last 5 lines are returned empty.
darkDercane 3-Jan-12 16:01pm    
maybe some line is throwing an error,if i was u, i will check the try catch blocks, notice that u are not controlling efectively any errors, hummm a continue in the catch maybe or a Debug.Write to see whats happening :P
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900