App.config modification operation

xiaoxiao2021-03-06  40

Public class classconfigurationSettings {public classconfigurationSettings () {}

///

/// Modify the configuration file (database connection string) /// /// public static void updateconfig (string p_stroyal, string p_strvalue ) {Try {string m_strfullpath = ""; askEMBLY ASM = askEMBLY.GETEXECUTINGASSEMBLY (); xmldocument xmldoc = new xmldocument ();

m_strfullpath = asm.location.substring (0, (asm.location.lastindexof ("//") 1)) "Youapplication.exe.config"; xmldoc.Load (m_strfullpath);

XmlNodelist NodeList = XmLDoc.selectsinglenode ("/ configuration / appsettings"). ChildNodes; Foreach (XMLNode Xn In nodelist) // Traverse all child nodes {XMLELEMENT XE = (XMLELEMENT) XN;

if (xe.GetAttribute ( "key") IndexOf (p_strKey) = -1.!) {xe.SetAttribute ( "value", p_strValue);}} xmlDoc.Save (m_strFullPath);} catch (System.NullReferenceException NullEx) { THROW NULLEX;} catch (exception ex) {throw ex;}}

}

转载请注明原文地址:https://www.9cbs.com/read-78857.html

New Post(0)