public void LoadXML(string path) { ConfigXmlDocument xml = new ConfigXmlDocument(); xml.Load("config.xml"); XmlNode node = xml.SelectSingleNode("/configuration/appSettings"); EDPCheckHelper.st.STID = Convert.ToInt32(node.SelectSingleNode("st").Attributes["value"].Value); EDPCheckHelper.st.zctime = Convert.ToInt32(node.SelectSingleNode("zctime").Attributes["value"].Value); EDPCheckHelper.st.gztime = Convert.ToInt32(node.SelectSingleNode("gztime").Attributes["value"].Value); EDPCheckHelper.st.dd = node.SelectSingleNode("dd").Attributes["value"].Value; EDPCheckHelper.st.ph = node.SelectSingleNode("admin").Attributes["value"].Value; var ips = xml.SelectSingleNode("/configuration/Check/PC"); foreach (XmlNode xn in ips.ChildNodes) { EDPCheckHelper.EDPMsg em = new EDPCheckHelper.EDPMsg(); em.MacName = xn.Attributes["key"].Value; em.IP = xn.Attributes["value"].Value; em.MsgTime = DateTime.Now; em.succes = true; em.Type = Convert.ToInt32(xn.Attributes["type"].Value); EDPCheckHelper.ems.Add(em.MacName, em); } }
private void LoadWorlds() { try { GLSDatacenterInfoServer svc = new GLSDatacenterInfoServer(); Datacenter[] dc = svc.GetDatacenters(Settings.Game); List <Datacenter> dataCenters = dc.ToList(); worlds = dataCenters[0].Worlds.ToList(); cbServer.DataSource = worlds; if (!string.IsNullOrEmpty(Settings.DefaultServer)) { cbServer.SelectedIndex = cbServer.FindStringExact(Settings.DefaultServer); } ConfigXmlDocument cxd = new ConfigXmlDocument(); cxd.Load(dataCenters[0].LauncherConfigurationServer); dataCenterSettings = new Dictionary <string, string>(); foreach (XmlNode node in cxd["configuration"]["appSettings"].ChildNodes) { if (node.Attributes != null) { dataCenterSettings.Add(node.Attributes["key"].Value, node.Attributes["value"].Value); } } } catch (Exception ex) { MessageBox.Show("Error getting datacenters\n" + ex.Message); } GetServerStatuses(); }
public LauncherData(string workingDir) { dataCenterConfig = new ConfigXmlDocument(); dataCenterConfig.Load(System.IO.Path.Combine(workingDir, "TurbineLauncher.exe.config")); gameName = GetAppSetting(dataCenterConfig, "DataCenter.GameName"); dataCenterServer = GetAppSetting(dataCenterConfig, "Launcher.DataCenterService.GLS"); GLSDatacenterInfoServer svc = new GLSDatacenterInfoServer(); svc.Url = dataCenterServer; Datacenter[] dc = svc.GetDatacenters(gameName); dataCenter = dc[0]; dataCenterConfig = new ConfigXmlDocument(); dataCenterConfig.Load(dataCenter.LauncherConfigurationServer); dataCenterSettings = new Dictionary <string, string>(); foreach (XmlNode node in dataCenterConfig["configuration"]["appSettings"].ChildNodes) { if (node.Attributes != null) { dataCenterSettings.Add(node.Attributes["key"].Value, node.Attributes["value"].Value); } } worlds = dataCenter.Worlds.ToDictionary(w => w.Name, w => w); }
public static bool SaveSection(string fileName, string name, MailerConfiguration section) { System.Configuration.ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(fileName); XmlNode configNode = doc.ChildNodes[1]; foreach (XmlNode node in configNode.ChildNodes) { if (node.Name == name) { configNode.RemoveChild(node); } } XmlNode newNode = section.CreateNode(doc, name); configNode.AppendChild(newNode); doc.Save(fileName); return(true); } catch { return(false); } }
/// <summary> /// Загрузить конфиг-файл. /// </summary> internal static void LoadXmlConfig() { string fileName = DefaultProgramFullFileName; bool create = false; if (File.Exists(fileName)) { try { localParams.Load(fileName); } catch (Exception) { create = true; } } if (create) { localParams = new ConfigXmlDocument(); XmlDeclaration declaration = localParams.CreateXmlDeclaration("1.0", "utf-8", "yes"); localParams.AppendChild(declaration); XmlNode root = localParams.CreateElement(ProgramConfiguraton.trainerRootNodeName); localParams.AppendChild(root); } }
internal void SaveSettings() { // Load the web.config file var filename = HttpContext.Current.Server.MapPath("~/web.config"); var webconfig = new ConfigXmlDocument(); webconfig.Load(filename); var node = webconfig.SelectSingleNode("/configuration/connectionStrings/add[@name='RedisCachingProvider']"); SaveAttribute(node, "connectionString", ConnectionString); node = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching"); SaveAttribute(node, "defaultProvider", CachingProviderEnabled ? "RedisCachingProvider" : "FileBasedCachingProvider"); node = webconfig.SelectSingleNode("/configuration/dotnetnuke/outputCaching"); SaveAttribute(node, "defaultProvider", OutputCachingProviderEnabled ? "RedisOutputCachingProvider" : "MemoryOutputCachingProvider"); node = webconfig.SelectSingleNode("/configuration/dotnetnuke/caching/providers/add[@name='RedisCachingProvider']"); SaveAttribute(node, "useCompression", UseCompression.ToString()); SaveAttribute(node, "silentMode", SilentMode.ToString()); SaveAttribute(node, "keyPrefix", KeyPrefix); node = webconfig.SelectSingleNode("/configuration/dotnetnuke/outputCaching/providers/add[@name='RedisOutputCachingProvider']"); SaveAttribute(node, "useCompression", UseCompression.ToString()); SaveAttribute(node, "silentMode", SilentMode.ToString()); SaveAttribute(node, "keyPrefix", KeyPrefix); webconfig.Save(filename); // Clear the cache DotNetNuke.Services.Cache.CachingProvider.Instance().PurgeCache(); }
[Fact] // GetLineNumber (XmlNode) // Doesn't pass on Mono // [Category("NotWorking")] public void GetLineNumber2() { using (var temp = new TempDirectory()) { XmlNode node; int line; string xmlfile = Path.Combine(temp.Path, "test.xml"); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("test")); doc.Save(xmlfile); node = new XmlDocument(); line = ConfigurationErrorsException.GetLineNumber(node); Assert.Equal(0, line); doc = new XmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; line = ConfigurationErrorsException.GetLineNumber(node); Assert.Equal(0, line); doc = new ConfigXmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; line = ConfigurationErrorsException.GetLineNumber(node); Assert.Equal(1, line); } }
public void GetLineNumber2() { XmlNode node; int line; string xmlfile = Path.Combine(foldername, "test.xml"); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("test")); doc.Save(xmlfile); node = new XmlDocument(); line = ConfigurationErrorsException.GetLineNumber(node); Assert.AreEqual(0, line, "#1"); doc = new XmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; line = ConfigurationErrorsException.GetLineNumber(node); Assert.AreEqual(0, line, "#2"); doc = new ConfigXmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; line = ConfigurationErrorsException.GetLineNumber(node); Assert.AreEqual(1, line, "#3"); }
public void GetFilename2() { XmlNode node; string filename; string xmlfile = Path.Combine(foldername, "test.xml"); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("test")); doc.Save(xmlfile); node = new XmlDocument(); filename = ConfigurationErrorsException.GetFilename(node); Assert.IsNull(filename, "#1"); doc = new XmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; filename = ConfigurationErrorsException.GetFilename(node); Assert.IsNull(filename, "#2"); doc = new ConfigXmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; filename = ConfigurationErrorsException.GetFilename(node); Assert.AreEqual(xmlfile, filename, "#3"); }
/// <summary> /// Update RunTimeData appSettings sections /// Add a new key /// </summary> /// <param name="key"></param> /// <param name="value"></param> public static void AddKeyAppSettings(string key, string value) { //Update custom configuration sections - Add a new key ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\"; //var xmlDir = fileDir + "RunTimeData.xml"; //Replace with get xmlDir Method() xmlDoc.Load(xmlDir); // create new node <add key="New Key" value="New Key Value1" /> var node = xmlDoc.CreateElement("add"); //node.SetAttribute("key", "New Key"); //node.SetAttribute("value", "New Key Value1"); node.SetAttribute("key", key); node.SetAttribute("value", value); xmlDoc.SelectSingleNode("//appSettings").AppendChild(node); //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); xmlDoc.Save(xmlDir); ConfigurationManager.RefreshSection("//appSettings"); }
[Fact] // GetFilename (XmlNode) // Doesn't pass on Mono // [Category("NotWorking")] public void GetFilename2() { using (var temp = new TempDirectory()) { XmlNode node; string filename; string xmlfile = Path.Combine(temp.Path, "test.xml"); XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateElement("test")); doc.Save(xmlfile); node = new XmlDocument(); filename = ConfigurationErrorsException.GetFilename(node); Assert.Null(filename); doc = new XmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; filename = ConfigurationErrorsException.GetFilename(node); Assert.Null(filename); doc = new ConfigXmlDocument(); doc.Load(xmlfile); node = doc.DocumentElement; filename = ConfigurationErrorsException.GetFilename(node); Assert.Equal(xmlfile, filename); } }
XmlDocument GetInnerDoc(XmlDocument doc, int i, string [] sectionPath) { if (++i >= sectionPath.Length) { return(doc); } if (doc.DocumentElement == null) { return(null); } XmlNode node = doc.DocumentElement.FirstChild; while (node != null) { if (node.Name == sectionPath [i]) { ConfigXmlDocument result = new ConfigXmlDocument(); result.Load(new StringReader(node.OuterXml)); return(GetInnerDoc(result, i, sectionPath)); } node = node.NextSibling; } return(null); }
/// <summary> /// Update RunTimeData custom configuration sections /// Edit an existing key's value /// </summary> /// <param name="key"></param> /// <param name="value"></param> public static void UpdateKeyConfigSectionData(string key, string value) { //First get the current environment from the appSettings section var environment = AppConfig.GetAppSettingsValue("Environment"); // Update custom configuration sections - Edit an existing key's value ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); //this dir accesses the \bin runtime location //not the project app.config file //xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\"; //var xmlDir = fileDir + "RunTimeData.xml"; //Replace with get xmlDir Method() xmlDoc.Load(xmlDir); //Update the key value //xmlDoc.SelectSingleNode("//Local/add[@key='Test']").Attributes["value"].Value = "New Value6"; var node = "//" + environment + "/add[@key='" + key + "']"; xmlDoc.SelectSingleNode(node).Attributes["value"].Value = value; //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); xmlDoc.Save(xmlDir); ConfigurationManager.RefreshSection("//" + environment); }
/// <summary> /// Update RunTimeData custom configuration sections /// Delete an existing key /// </summary> /// <param name="key"></param> public static void DeleteKeyConfigSectionData(string key) { //First get the current environment from the appSettings section var environment = AppConfig.GetAppSettingsValue("Environment"); //Update custom configuration sections - Add a new key ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); //var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; //var fileDir = projectDir + @"\AcceptanceTests\DataFiles\"; //var xmlDir = fileDir + "RunTimeData.xml"; //Replace with get xmlDir Method() xmlDoc.Load(xmlDir); //XmlNode node = xmlDoc.SelectSingleNode("//Dev/add[@key='Key1']"); var nodeString = "//" + environment + "/add[@key='" + key + "']"; XmlNode node = xmlDoc.SelectSingleNode(nodeString); node.ParentNode.RemoveChild(node); //xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); xmlDoc.Save(xmlDir); ConfigurationManager.RefreshSection("//" + environment); }
private string GetConnectionString(string strPathToConfigFile, string strAppSettingsKey) { try { ConfigXmlDocument doc = new ConfigXmlDocument(); doc.Load(strPathToConfigFile); XmlNode nodeKey = doc.SelectSingleNode("//appSettings/add[@key='" + strAppSettingsKey + "']"); string strEncValue = nodeKey.Attributes["value"].Value.ToString(); string strDecValue = ICICRYPT.Reversible.StrDecode(strEncValue, 2026820330, true); // MessageBox.Show(strDecValue); SqlConnection objConn = new SqlConnection(strDecValue); objConn.Open(); objConn.Close(); objConn.Dispose(); return(strDecValue); } catch (System.Exception ex) { MessageBox.Show(this, "Error obtaining connection to " + strLocation + " database\n\n\"" + ex.Message + "\"\n" + ex.StackTrace, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } return(null); }
private void CreateAddInConfigurationFile(string serviceDirectory) { string addInConfigurationFile; System.Configuration.Configuration config; System.Configuration.ConfigXmlDocument xml = new ConfigXmlDocument( ); XmlNodeList nodes; addInConfigurationFile = Path.Combine(serviceDirectory, "service.config"); config = ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); config.SaveAs(addInConfigurationFile); xml.Load(addInConfigurationFile); nodes = xml.GetElementsByTagName("appSettings"); if (nodes.Count > 0) { nodes [0].ParentNode.RemoveChild(nodes [0]); xml.Save(addInConfigurationFile); } }
private void ModifyAppInsightsConfigFile(bool removeSettings = false) { var configFile = Server.MapPath("~/ApplicationInsights.config"); if (!File.Exists(configFile)) { File.Copy(Server.MapPath("~/DesktopModules/AppInsights/ApplicationInsights.config"), configFile); } // Load the ApplicationInsights.config file var config = new ConfigXmlDocument(); config.Load(configFile); var key = removeSettings ? string.Empty : ModuleSettings.GetValueOrDefault("InstrumentationKey", string.Empty); const string namespaceUri = "http://schemas.microsoft.com/ApplicationInsights/2013/Settings"; var nsmgr = new XmlNamespaceManager(config.NameTable); nsmgr.AddNamespace("nr", namespaceUri); // Change instrumentation key var keyNode = config.SelectSingleNode("//nr:InstrumentationKey", nsmgr); if (keyNode != null) { keyNode.InnerText = key; } // Save the modifications config.Save(configFile); }
public registerReader() { if (cfgDom == null) { cfgDom = new ConfigXmlDocument(); } cfgDom.Load(string.Format("{0}{1}", System.AppDomain.CurrentDomain.BaseDirectory, CFG_FILE)); }
private void change_net_settings_Click(object sender, EventArgs e) { //Tomo los valores de ambos cuadros de texto string IPstr = new_IP_txt.Text.Trim(); string PORTstr = new_PORT_txt.Text.Trim(); if (IPstr == "") { string message = "Changes cannot be applied - IP Address empty"; string title = "Error"; MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); return; } if (PORTstr == "") { string message = "Changes cannot be applied - PORT empty"; string title = "Error"; MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); return; } //Editar el App.config ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); foreach (System.Xml.XmlElement el in xmlDoc.DocumentElement) { if (el.Name.Equals("appSettings")) { foreach (System.Xml.XmlNode node in el.ChildNodes) { if (node.Attributes[0].Value == "IP_address") { node.Attributes[1].Value = IPstr; } if (node.Attributes[0].Value == "PORT") { node.Attributes[1].Value = PORTstr; } } } xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ConfigurationManager.RefreshSection("appSettings"); } MessageBox.Show("Changes applied successfully"); this.Close(); }
protected void btnGetTheatres_Click(object sender, EventArgs e) { //haetaan FinnKinon teatterit listboxiin ConfigXmlDocument doc = new ConfigXmlDocument(); doc.Load(urlToTheatres); XmlNodeList nodes = doc.DocumentElement.SelectNodes("TheatreArea"); foreach (XmlNode node in nodes) { ListItem li = new ListItem(node["Name"].InnerText,node["ID"].InnerText); myListBox.Items.Add(li); } }
public void CanLoadSchemaImportingOtherSchemaByRelativePath() { string schemaLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "NamespaceParserRegistryTests_TestSchema.xsd"); NamespaceParserRegistry.RegisterParser(new TestNamespaceParser(), "http://www.example.com/brief", schemaLocation); XmlReader vr = XmlUtils.CreateValidatingReader(new StringResource( @"<?xml version='1.0' encoding='UTF-8' ?> <brief class='foo' /> ").InputStream, NamespaceParserRegistry.GetSchemas(), null); ConfigXmlDocument newDoc = new ConfigXmlDocument(); newDoc.Load(vr); }
private ConfigXmlDocument LoadConfigDocument(string configPath) { try { ConfigXmlDocument configXmlDocument = new ConfigXmlDocument(); configXmlDocument.Load(configPath); return(configXmlDocument); } catch (Exception ex) { throw new Exception("目录下的配置文件有异常,请检查!"); } }
public object Create(object parent, object configContext, XmlNode section) { object result = parent; XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); if (fileAttribute == null && fileAttribute.Value.Length == 0) { return(new NameValueSectionHandler().Create(result, null, section)); } IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return(null); } string directory = Path.GetDirectoryName(configXmlNode.Filename); string absoluteFilePath = Path.GetFullPath(directory + fileAttribute.Value); if (!File.Exists(absoluteFilePath)) { throw new ConfigurationErrorsException(string.Format("external config file: {0} does not exists", absoluteFilePath)); } var configXmlDocument = new ConfigXmlDocument(); try { configXmlDocument.Load(absoluteFilePath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, absoluteFilePath, e.LineNumber); } if (section.Name != configXmlDocument.DocumentElement.Name) { throw new ConfigurationErrorsException(string.Format("Section name '{0}' in app.config does not match section name '{1}' in file '{2}'", section.Name, configXmlDocument.DocumentElement.Name, absoluteFilePath)); } var nodeToDecrypt = configXmlDocument.DocumentElement["EncryptedData"]; if (nodeToDecrypt == null) { throw new ConfigurationErrorsException(string.Format("External encrypted file {0} does not contain EncryptedData element", absoluteFilePath)); } var protectionProvider = new DpapiProtectedConfigurationProvider(); var decryptedConfigSection = protectionProvider.Decrypt(nodeToDecrypt); result = new NameValueSectionHandler().Create(result, null, decryptedConfigSection); return(result); }
/// <summary> /// Actually load object definitions from the specified XML file. /// </summary> /// <param name="stream">The input stream to read from.</param> /// <param name="resource">The resource for the XML data.</param> /// <returns></returns> protected virtual int DoLoadObjectDefinitions(Stream stream, IResource resource) { try { // create local copy of data byte[] xmlData = IOUtils.ToByteArray(stream); XmlDocument doc; // loop until no unregistered, wellknown namespaces left while (true) { XmlReader reader = null; try { MemoryStream xmlDataStream = new MemoryStream(xmlData); reader = CreateValidatingReader(xmlDataStream); doc = new ConfigXmlDocument(); doc.Load(reader); break; } catch (RetryParseException) { if (reader != null) { reader.Close(); } } } return(RegisterObjectDefinitions(doc, resource)); } catch (XmlException ex) { throw new ObjectDefinitionStoreException(resource.Description, "Line " + ex.LineNumber + " in XML document from " + resource + " is not well formed. " + ex.Message, ex); } catch (XmlSchemaException ex) { throw new ObjectDefinitionStoreException(resource.Description, "Line " + ex.LineNumber + " in XML document from " + resource + " violates the schema. " + ex.Message, ex); } catch (ObjectDefinitionStoreException) { throw; } catch (Exception ex) { throw new ObjectDefinitionStoreException("Unexpected exception parsing XML document from " + resource.Description + "Inner exception message= " + ex.Message, ex); } }
/// <summary> /// 描画後に文字列を埋める処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WindowGeneralBase_ContentRendered(object sender, EventArgs e) { bool lcflag = false; string lcuser = string.Empty; string lcpass = string.Empty; try { FileInfo fi = new System.IO.FileInfo(GetLocalConfigFilePath()); if (fi.Exists) { ConfigXmlDocument cdoc = new ConfigXmlDocument(); cdoc.Load(fi.FullName); var cfgs = cdoc.SelectNodes("/configuration/settings/add"); foreach (var item in cfgs) { var key = (item as XmlElement).Attributes.GetNamedItem("key").Value; var val = (item as XmlElement).Attributes.GetNamedItem("value").Value; switch (key) { case "LoginCheck": lcflag = string.IsNullOrWhiteSpace(val) ? false : Convert.ToBoolean(val); break; case "TextUr": lcuser = Utility.Decrypt(val); break; case "TextLr": lcpass = Utility.Decrypt(val); break; } } } } catch (Exception) { } finally { this.ライセンス情報記憶 = lcflag; if (lcflag) { this.ユーザーID = lcuser; if (lcpass.Trim() != string.Empty) { this.PASSWORD.SetPassword(lcpass); } } } }
protected void btnGetTheatres_Click(object sender, EventArgs e) { //haetaan FinnKinon teatterit listboxiin ConfigXmlDocument doc = new ConfigXmlDocument(); doc.Load(urlToTheatres); XmlNodeList nodes = doc.DocumentElement.SelectNodes("TheatreArea"); foreach (XmlNode node in nodes) { ListItem li = new ListItem(node["Name"].InnerText, node["ID"].InnerText); myListBox.Items.Add(li); } }
public static string GetSiteSetting(System.Web.HttpServerUtility server, string name) { ConfigXmlDocument cfxd = new ConfigXmlDocument(); cfxd.Load(server.MapPath(SiteConfigPath)); try { string value = cfxd.GetElementsByTagName(name)[0].InnerText; return value; } catch { return ""; } }
/// <summary> /// 获取配置文件 /// </summary> /// <param name="server"></param> /// <param name="name"></param> /// <returns></returns> public static string GetSiteSetting(System.Web.HttpServerUtility server, string name) { ConfigXmlDocument cfxd = new ConfigXmlDocument(); cfxd.Load(server.MapPath(SiteConfigPath)); try { string value = cfxd.GetElementsByTagName(name)[0].InnerText; return(value); } catch { return(""); } }
public ConfigFile(string filename, bool createIfNecessary) { this.filename = filename; config = new ConfigXmlDocument(); if (File.Exists(filename)) { // Load the file if it already exists config.Load(filename); } else if (createIfNecessary) { // Create the file since it doesn't exist using (StreamWriter w = File.CreateText(filename)) { w.Write("<configuration></configuration>"); } config.Load(filename); } else { throw new FileNotFoundException("The configuration file \"" + filename + "\" was not found.", filename); } }
private ConfigSectionResource CreateConfigSectionResource(string filename) { ConfigXmlDocument xmlDoc = new ConfigXmlDocument(); Uri testUri = TestResourceLoader.GetUri(this, filename); xmlDoc.Load("test config section", testUri.AbsoluteUri); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("od", "http://www.springframework.net"); XmlElement configElement = (XmlElement)xmlDoc.SelectSingleNode("//configuration/spring/od:objects", nsmgr); ConfigSectionResource csr = new ConfigSectionResource(configElement); return(csr); }
public static MailerConfiguration GetSection(string fileName, string name) { System.Configuration.ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(fileName); XmlNode node = doc.GetElementsByTagName(name)[0]; IConfigurationSectionHandler handler = new UniMail.ConfigurationHandler(); return(handler.Create(null, null, node) as UniMail.MailerConfiguration); } catch { return(null); } }
public static ConfigXmlDocument GetConfigXmlDocument(string configUrl = "") { string file = configUrl; if (string.IsNullOrEmpty(file)) { file = Application.StartupPath + @"\GlobalAppConfig.config"; } if (File.Exists(file)) { ConfigXmlDocument cxd = new ConfigXmlDocument(); cxd.Load(file); return(cxd); } return(null); }