大家好,我想把我程序里的一些东西,保存下来,以便下次读取,本来写在ini文件里面,譬如
[APP1]
Title=Office
CopyRight=MS
Version=2K3
[APP2]
Title=SyamantecNortonVirus
CopyRight=Symantec
Version=10.0.2.2002现在我想把这个内容放在一个xml文件里面,然后写个寒暑 ,fun(section,item)就可以找到具体某个值,譬如fun("APP1","Title"),就可以返回Office,不知道可以办到不?如果可以,怎么办到呢?分不多,请帮帮忙!

解决方案 »

  1.   

    完全可以,ini文件是过时的东西!
      

  2.   

    应该可以吧
      
    *****************************************************************************
    欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码) 
    http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  3.   

    using System.Xml;
    using System.IO;读
    string FileName = HttpContext.Current.Server.MapPath("路径");
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(FileName);            //get all child nodes of BannerContent 
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("BannerContent").ChildNodes;            //over all nodes
                foreach (XmlNode xn in nodeList)
                {
                    //change child node type to XmlElement
                    XmlElement xe = (XmlElement)xn;                if (xe.GetAttribute("Name") == "ChangeColor")
                    {
                        if (xe.GetAttribute("Visible") == "true")
                        {
                            if (us.GetFirstRoleId() != -1)
                            {
                                ChangeColorIcon = "changeicon";
                                DesktopPortalBanner_ChangeColor = lc.GetLanguageDescription("DesktopPortalBanner_ChangeColor");
                            }
                        }
                    }
    }写string filePathDesktopSrc = Server.MapPath("路径");
                if (!File.Exists(filePathDesktopSrc))
                {
                    validateFileExist.ErrorMessage = BannerSrcPath.Text + "  " +
                        lc.GetLanguageDescription("ModuleDefinitions_Error");
                    validateFileExist.IsValid = false;
                    return;
                }            xmlDoc.Load(FileName);            //get all child nodes of BannerContent 
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("BannerContent").ChildNodes;            #region over all nodes
                foreach (XmlNode xn in nodeList)
                {
                    XmlElement xe = (XmlElement)xn;
                    if (xe.GetAttribute("Name") == "ChangeColor")
                    {
                        if (this.ManageChangeColor.Checked == true)
                        {
                            xe.SetAttribute("Visible", "true");
                        }
                        else
                        {
                            xe.SetAttribute("Visible", "false");
                        }
                    }
                }
                #endregion            xmlDoc.Save(FileName);//save xml file
      

  4.   

    当然可以, 我都用xml做参数文件的。添加一个app.config,
      <appSettings>
        <add key="SurroundingAreaIncluded" value="0"/>
        <add key="WaitPerPageSEC" value="3333" />
      </appSettings>在程序中ConfigurationManager.AppSettings.Get("WaitPerPageSEC").Trim();当然可以自己新建xml
      

  5.   

    以上帝之名保证可以
    <root>
    <APP1 Title="Office" CopyRight="MS" Version="2K3"/>
    <APP2 Title="SyamantecNortonVirus" CopyRight="Symantec" Version="10.0.2.2002"/>
    </root>
      

  6.   

    完全可以,只有有过ini背景的还在用这过时的玩意儿,新兴的都是用xml
      

  7.   

    呵呵,只要方便就行。xml不错,不过如果只是存储一点配置信息,未见得比ini好多少。看自己的习惯。方便好用就好。
    有句话怎么说的来着:把时髦的技术挂在嘴边,不如把过时的技术记在心里。
      

  8.   

    可以呀,
    Read/Write XML files, Config files, INI files, or the Registry
    By Alvaro Mendez
    http://www.codeproject.com/csharp/readwritexmlini.asp
      

  9.   

    ini 是win98开始淘汰的东西了.
      

  10.   

    VS2005里,菜单:“项目=>(项目名)属性.. 打开项目属性下面有个"设置"。这里直接可以设置应用程序的属性,会自动生成和修改app.config,十分方便。
    注意"范围":Application则是只读的,User是运行时可修改的。
    发布的时候注意加密配置文件中的敏感信息。
    用户通过应用程序修改设置,设置会在
    C:\Documents and Settings\用户名\Application Data\公司名
    下生成一个user.config 保存用户修改的设置。
    而且可以直接绑定到控件,控件里的数据=>ApplicationSettings属性里设置。
    ======================================
    使用方法我举个例子:
    =====================================
    我的项目名是MyCSDN
    我在项目属性设置一个名myStr,string类型, 值hello
    程序里首先引用 :项目名.Properties;
    例如,我们的:
    using MyCSDN.Properties;然后            Settings setting = new Settings();
                this.textBox1.Text=setting.myStr;//读取配置myStr
                setting.Save();//保存配置
                setting.Reset();//还原默认值
                setting.Reload();//读取最后一次保存的值
    ====================
    如果是绑定到控件的,窗体建立的时候会自动读取,非常方便:)
      

  11.   

    XML才是主流,ini早淘汰了,不过也不是不能用,建议好好研究一下XML的各种相关技术以及.NET中XML命名空间下的类,很有用的
      

  12.   

    如果东西不多的话ini还是比较方便的。
      

  13.   

    万分感谢zhzuo(秋枫),信息非常有用,我就打算用这种方式了