Exemple #1
0
        private void btnSelectConfig_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                var xmlConfig = new XmlConfig
                {
                    ConfigFile = openFileDialog.FileName
                };

                List <string> connections = xmlConfig.GetChildElements("//connectionStrings", "connectionString");

                if (connections.Count > 0)
                {
                    var frm = new SaveConnectionAsForm();
                    if (DialogResult.OK == frm.ShowDialog())
                    {
                        XmlConfig.Instance.SetValue("//MyConnectionStrings//add[@key='" + frm.ConnectionName + "']", connections[0]);
                        DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    MessageBox.Show("No connection string found in this configuration file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Close();
            }
        }