Ejemplo n.º 1
0
        //---Метод: Удаляет подключение из Config файла----------------------------------------------------------------------
        public static void DeleteConnection(string ConnectionName)
        {
            try
            {
                //DeSelectAllConnections();
                XmlDocument document = new XmlDocument();
                document.Load(path);
                XmlElement RootElement = document.DocumentElement;

                foreach (XmlElement El in RootElement) // Пробежимся по Элементам Корневого элемента
                {
                    if (El.Name == "Connections")      // Если имя элемента "Connections"
                    {
                        foreach (XmlNode childnode in El.ChildNodes)
                        {
                            if (childnode.Name == "Connection")
                            {
                                XmlNode атрибут = childnode.Attributes.GetNamedItem("Name");

                                if (Cryption.Decrypt(атрибут.Value) == ConnectionName) // Если "Название" равно "Осень"
                                {
                                    El.RemoveChild(childnode);
                                }
                            }
                        }
                    }
                }
                document.Save(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "XmlClass.DeleteConnection(string ConnectionName)");
            }
        }