可以参考msdn上安装程序如何自带数据库安装的文章

解决方案 »

  1.   

    为什么要写入*.config文件??ms就不赞同这样的风格。config文件是提供给系统管理员控制应用程序的。你所说的配置,存储到“独立存储比较合适吧”。
      

  2.   

    独立存储——IsolatedStorage see  msdn for detail
      

  3.   

    我也想知道,IsolatedStorage是什么,怎么用。能实现什么。我看了msdn,还没什么概念
      

  4.   

    把它当做一个xml文件载入改写并放回去就可以了。函数实现代码如下:void editwebconfig(string conn)           //conn是需要改写的字符串内容
    {
    Assembly asm = Assembly.GetExecutingAssembly();
    string strPath = asm.Location;
    string[] ary = strPath.Split('\\');   //config文件目录
    ary[ary.Length-1] = "web.config";     //confing文件名
    strPath = string.Join("\\", ary);

    XmlDocument xmldoc= new XmlDocument();
    xmldoc.Load(strPath); XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
    foreach(XmlElement element in topM)
    {
    if(element.Name.ToLower()=="appsettings")  //找到要改写的字段名
    {
    XmlNodeList _node=element.ChildNodes;
    if ( _node.Count >0 ) 
    {
    foreach(XmlElement el in _node)
    {
    el.Attributes["value"].Value=conn;                                //查找并改写
    }
    }
    }
    }
    xmldoc.Save(strPath);   //保存改写文件
    }
      

  5.   

    app.config文件通常是用来手工输入信息然后在程序里面动态读取这些信息。所以.Net里面没有内置类来写入app.config,ms也不建议使用程序修改app.config文件,但是你还是可以使用Xml的类来操作app.config,具体方法请参考一下两篇文章:
    http://www.codeproject.com/csharp/AnyConfig.asp
    http://www.codeproject.com/csharp/ReadWriteXmlIni.asp