2012-03-13 2 views
1

구성 섹션 디자이너 (csd)를 사용하여 응용 프로그램에 XML 구성 파일을 생성했습니다.csd를 사용하여 생성 된 xml에 읽기/쓰기

1

txtbox_username.Text = ConfigurationManager.AppSettings["userName"]; 
같은 특정 값 (해당 분야에 의해 검색), 뭔가를 읽어

는 지금, 나는 (C#을에)이 XML 파일로 작업하고 2 일을 할 2.

는 특정 값,

config.AppSettings.Settings["userName"].Value = txtbox_username.Text; 

config.Save(ConfigurationSaveMode.Modified); 

ConfigurationManager.RefreshSection("configuration"); 
    같은 것을 쓰기 ...


<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
add key="userName" value="Value1" 
    </appSettings> 
</configuration> 

하지만 CSD는 XML은 서로 다른 모양 생성 :3210

  • 추신 :이은 다음과 같습니다 일반 XML 파일의 읽기/쓰기 내가 읽어 실시합니다 어떻게
    <?xml version="1.0"?> 
    <configuration> 
        <configSections> 
        <section name="sectionName" type="Sample.ConfigurationSection.sectionName, Sample.ConfigurationSection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
        </configSections> 
        <sectionName xmlns="Sample.ConfigurationSection"> 
        <logFile debugLevel="3" filePath="c:\new" maxFileCount="10" maxFileLength="1000"/> 
        <results path="C:\Results"/> 
        <details user="blabla" pass="12345" code="abc"/> 
        <stuff fromAddress="[email protected]" toAddress="[email protected]" sendMail="true""/> 
        </sectionName> 
        <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
        </startup> 
    </configuration> 
    

    여기에서 예를 들어 사용자/전달/코드 입력란을 편집하고 저장하고 싶습니다.

  • 답변

    0
    한마디로

    (그리고 이러한 확장 사용 : http://searisen.com/xmllib/extensions.wiki)는 사용자가 읽기/쓰기이 작업을 수행 할 수 있습니다,

    XElement file = XElement.Load(xmlFile); 
    XNamespace ns = "Sample.ConfigurationSection"; 
    XElement section = file.GetElement(ns + "sectionName"); 
    string user = section.Get("details/user", string.Empty); 
    section.Set("details/user", "bubba", true); // true = set as attribute 
    file.Save(xmlFile); 
    
    관련 문제