public void OpenFile() { string fileName = string.Empty; // System.Windows.Forms.OpenFileDialog OpenFileDialog = new System.Windows.Forms.OpenFileDialog(); // OpenFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; OpenItemDialog oid = new OpenItemDialog { // oid.BrowseFilter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; Title = "Open a text file", Filter = ItemFilters.textFiles, MultiSelect = true }; bool?ok = oid.ShowDialog(); //System.Threading.Thread.Sleep(300); if (ok == true) { IEnumerable <Item> selected = oid.Items; fileName = selected.First().Path; //MessageBox.Show("LayerList is updated using "+fileName); //pass the text file path to Button1, so it can read the file too. AddLayersToMap addLayersToMap = AddLayersToMap.Current; Button1 b1 = addLayersToMap.B1; //// get the instance of the current one, do not create a new Button1 //Button1 b1 = new Button1(); if (b1 != null) { b1.FILE_NAME = fileName; if (b1.Enabled == false) { b1.Enabled = true; } } readText(fileName); } else { MessageBox.Show("No file selected"); return; } }
/// <summary> /// The on comboBox selection change event. /// </summary> /// <param name="item">The newly selected combo box item</param> protected override void OnSelectionChange(ComboBoxItem item) { if (item == null) { return; } if (string.IsNullOrEmpty(item.Text)) { return; } // TODO Code behavior when selection changes. AddLayersToMap addLayersToMap = AddLayersToMap.Current; Button1 btn = addLayersToMap.B1 ?? new Button1(); if (item.Text.ToUpper() != "LAYERNAME") { if (File.Exists(layerNameAndPath[item.Text]) || layerNameAndPath[item.Text].ToUpper().Contains("SERVER")) //make sure the path exists { btn.AddLayer(layerNameAndPath[item.Text]); //get the path with dictionary key, then call AddLayer } else { System.Windows.MessageBox.Show(string.Format("{0} doesn't exist or is not accessible", layerNameAndPath[item.Text])); } } //string FILE_NAME = @"C:\Work\GIS\data\shpList.txt"; //string[] lines = File.ReadAllLines(FILE_NAME);//.Where(x =>!string.IsNullOrWhiteSpace(x)); //foreach (string line in lines) //{ // string[] content = line.Split(','); // //Add(new ComboBoxItem(content[0])); // if (item.Text != "LayerName" && item.Text == content[0]) // { // btn.AddLayer(content[1]); // } //} }