Esempio n. 1
0
        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> currentDictionary = computers;
            //make a backup

            OpenFileDialog openFileDialog2 = new OpenFileDialog();
            openFileDialog2.Filter = "Text Files (*.txt) | *.txt|All files (*.*)|*.*";
            openFileDialog2.CheckPathExists = true;
            openFileDialog2.CheckFileExists = true;

            DialogResult openResult = openFileDialog2.ShowDialog();
            if (openResult == DialogResult.OK)
                 //readInComputerNames(openFileDialog2.FileName);
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (Stream input = File.OpenRead(openFileDialog2.FileName))
                    {
                        computers = (Dictionary<string, string>)bf.Deserialize(input);
                        UpdateListBoxes();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong\r\n" + ex.Message);
                }
        }
Esempio n. 2
0
 private int numberOfNotNullElements(Dictionary<string, string>.KeyCollection keyCollection)
 {
     int number=0;
     foreach (string element in keyCollection)
     {
         if (element != null)
         {
             number++;
         }
     }
     return number;
 }