Beispiel #1
0
        void Button3Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "Comma Separated Files (.csv)|*.csv|Txt Files (.txt)|*.txt|All Files (*.*)|*.*";
            ofd.FilterIndex = 1;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try {
                    String[] values = File.ReadAllText(String.Format("{0}", ofd.FileName)).Split(',');

                    // TODO: call the addExcludedItems method instead of duping the code
                    foreach (string v in values)
                    {
                        if (!String.IsNullOrEmpty(v))
                        {
                            int vn;
                            try {
                                vn = Convert.ToInt32(v);
                                if ((ex != null) && (ex.ids != null))
                                {
                                }
                                if (!ex.ids.Contains(vn))
                                {
                                    ex.ids.Add(vn);
                                }
                            }
                            catch (System.FormatException fe) { System.Console.Write(fe.ToString()); }
                        }
                    }
                    ex.saveFile();
                    refreshList();
                }
                catch (Exception fail) {
                    MessageBox.Show(String.Format("Failed to load {0}. Error: {1}", ofd.FileName, fail.ToString()));
                }
            }
        }