Thursday, 22 August 2013

c# windows programs remove duplicates not working

c# windows programs remove duplicates not working

Hi can i know why this code not working, it's working but it will also
remove non duplicates entry and for some lists it will throw some error
ex:
This list working but it will also remove http://test1.com
http://test.com
http://test.com
http://test1.com
http://1test.com
And with this lists will throw this "System.ArgumentNullException was
unhandled" error
http://test.com
http://test.com
http://test1.com
http://1test.com
http://etest.com



private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog buka = new OpenFileDialog();
buka.InitialDirectory = "";
buka.Filter = "Text files(*.txt)|*.txt|All files (*.*)|*.*";
buka.FilterIndex = 2;
buka.RestoreDirectory = true;
buka.Title = "Cari";
buka.ShowDialog();
string bukafile = buka.FileName;
if (!String.IsNullOrEmpty(bukafile))
{
StreamReader isiFile = File.OpenText(bukafile);
while (isiFile.Peek() != -1)
{
if (!listBox1.Items.Contains(isiFile.ReadLine()))
{
listBox1.Items.Add(isiFile.ReadLine());
}
}
isiFile.Close();
}
}

No comments:

Post a Comment