CreateElement() 공개 메소드

public CreateElement ( string prefix, string localName, string namespaceUri ) : XmlElement
prefix string
localName string
namespaceUri string
리턴 System.Xml.XmlElement
예제 #1
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();


        System.Configuration.ConfigXmlDocument config = new System.Configuration.ConfigXmlDocument();
        XmlElement   settings = config.CreateElement("Settings");
        XmlAttribute version  = config.CreateAttribute("Version");

        version.Value = "2.0";
        settings.Attributes.Append(version);
        config.AppendChild(settings);
        //SetDatabaseConfigList(settings);

        settings.AppendChild(config.CreateElement("HROneConfigFullPath"));
        settings["HROneConfigFullPath"].InnerText = HROneConfigFullPath;


        config.Save(filename);
    }
예제 #2
0
        /// <summary>
        /// 基于web.config模型的AppSettings设置
        /// </summary>
        /// <param name="configPath">配置文件路径,相对或完整路径。</param>
        /// <param name="key">健</param>
        /// <param name="Value">健的值</param>
        /// <returns>成功则为0,失败则返回异常信息。</returns>
        public static string SetAppSettings(string configPath, string key, string Value)
        {
            string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configPath);

            try
            {
                System.Configuration.ConfigXmlDocument xmlConfig = new System.Configuration.ConfigXmlDocument();
                xmlConfig.Load(configFile);

                System.Xml.XmlNode node = xmlConfig.SelectSingleNode("configuration/appSettings/add[@key='" + key + "']");
                if (node != null)
                {
                    node.Attributes["value"].Value = Value;
                }
                else
                {
                    XmlElement element = xmlConfig.CreateElement("add");
                    element.SetAttribute("key", key);
                    element.SetAttribute("value", Value);
                    node = xmlConfig.SelectSingleNode("configuration/appSettings");
                    node.AppendChild(element);
                }
                xmlConfig.Save(configFile);
                return("0");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
예제 #3
0
        public static bool UpdateConnectionString( )
        {
            Project pjt = Kit.GetProjectByName(Kit.SlnKeel.UIProjectName);

            if (pjt == null)
            {
                Common.ShowInfo("您尚未设置UI主界面项目, 因此无法自动配置连接字符串到你的app.config 或者web.config中!");
                return(true);
            }
            ProjectItem PI = null;

            for (int i = 1; i <= pjt.ProjectItems.Count; i++)
            {
                ProjectItem pix = pjt.ProjectItems.Item(i);
                if (pix.Name.ToLower().Contains("app.config") || pix.Name.ToLower().Contains("web.config"))
                {
                    PI = pix;
                    break;
                }
            }
            if (PI == null)
            {
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中未找到app.config 或者web.config,因此无法自动设置链接字符串配置", pjt.Name));
            }
            else
            {
                bool needUpdate = true;

                ConfigXmlDocument cxd = new System.Configuration.ConfigXmlDocument();

                cxd.Load(PI.get_FileNames(1));
                XmlNode xnx  = cxd.SelectSingleNode("descendant::configuration/connectionStrings");
                string  csss = GetProjectConfigNamespec(GetProjectLangType(GetProjectUI()));

                string name = "";
                if (pjt.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}")
                {
                    name = "Keel" + csss + ".ConnectionString";
                }
                else
                {
                    name = ((string)pjt.Properties.Item("RootNamespace").Value) + csss + ".ConnectionString";
                }
                if (xnx != null)
                {
                    for (int i = 0; i < xnx.ChildNodes.Count; i++)
                    {
                        if (xnx.ChildNodes[i].Attributes["name"].Value.Contains(name))
                        {
                            if (xnx.ChildNodes[i].Attributes["providerName"].Value != Kit.SlnKeel.ProviderName)
                            {
                                xnx.ChildNodes[i].Attributes["providerName"].Value = Kit.SlnKeel.ProviderName;
                            }
                            if (xnx.ChildNodes[i].Attributes["connectionString"].Value != Kit.SlnKeel.ConnectString)
                            {
                                xnx.ChildNodes[i].Attributes["connectionString"].Value = Kit.SlnKeel.ConnectString;
                            }
                            cxd.Save(PI.get_FileNames(1));
                            needUpdate = false;
                            break;
                        }
                    }
                }
                if (needUpdate)
                {
                    XmlNode      xn             = cxd.CreateNode("element", "add", "");
                    XmlAttribute xzproviderName = cxd.CreateAttribute("providerName");
                    xzproviderName.Value = Kit.SlnKeel.ProviderName;
                    XmlAttribute xaconnectionString = cxd.CreateAttribute("connectionString");
                    xaconnectionString.Value = Kit.SlnKeel.ConnectString;
                    XmlAttribute xaname = cxd.CreateAttribute("name");
                    xaname.Value = name;
                    xn.Attributes.Append(xaname);
                    xn.Attributes.Append(xaconnectionString);
                    xn.Attributes.Append(xzproviderName);
                    if (xnx == null)
                    {
                        XmlNode xnx1 = cxd.SelectSingleNode("descendant::configuration");
                        xnx = cxd.CreateElement("connectionStrings");
                        xnx1.AppendChild(xnx);
                    }
                    xnx.AppendChild(xn);
                    // cxd.SelectSingleNode("descendant::configuration/connectionStrings").InnerXml = xnx.InnerXml;
                    cxd.Save(PI.get_FileNames(1));
                    //;// = cxd.SelectSingleNode("descendant::configuration/connectionStrings/add[@name='" + appnamespace + ".Properties.Settings.ConnectionString']");
                    //if (xnl.Attributes["providerName"] != null && xnl.Attributes["connectionString"] != null)
                    //{

                    //}
                }
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中到app.config 或者web.config,已经设置了链接字符串{1}", pjt.Name, name));
            }
            return(true);
        }