C#中如何将一条一条的text文本写入XML文件中,并将XML文件中的Test文件显示在ComboBox列表中....请大家帮帮忙,,

解决方案 »

  1.   

    class Test 
    {
        public static void Main() 
        {
            string path = @"c:\temp\MyTest.txt";        // Delete the file if it exists.
            if (!File.Exists(path)) 
            {
                // Create the file.
                using (FileStream fs = File.Create(path)) 
                {
                    Byte[] info = 
                        new UTF8Encoding(true).GetBytes("This is some text in the file.");                // Add some information to the file.
                    fs.Write(info, 0, info.Length);
                }
            }        // Open the stream and read it back.
            using (StreamReader sr = File.OpenText(path)) 
            {
                string s = "";
                while ((s = sr.ReadLine()) != null) 
                {
                    ComboBox.Items.Add(s);
                }
            }
        }
    }
      

  2.   

    //写入
    System.Data.DataTable dtbl = .... //从数据库中检索的数据表
    dtbl.WriteXml("dataFile.xml");//读出,并绑定到 comboBox
    System.Data.DataTable dtbl = new System.Data.DataTable();
    dtbl.ReadXml("dataFile.xml");
    this.comboBox1.DataSource = dtbl;
      

  3.   

    我不是要从数据库中的表写入Xml文件的,我是将TextBox中文本添加写入XML文件的.
      

  4.   

    /// <summary>
      /// 从文本文件中读数据,返回一个数组
      /// </summary>
      public static string[] TextData
      {
        get 
        {
          
          string[] result = HttpContext.Current.Cache["Ustbwuyi_ReadTextData_1.0"] as string[];
          if (result == null)
          {
            List<string> list = new List<string>();
            using(StreamReader sr=new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Provider.txt"),Encoding.UTF8))
            {
              string str = "";
              while ((str = sr.ReadLine()) != null)
              {
                list.Add(str);
              }
              result = list.ToArray();
              HttpContext.Current.Cache.Insert("Ustbwuyi_ReadTextData_1.0", result, new System.Web.Caching.CacheDependency(HttpContext.Current.Server.MapPath("~/App_Data/Provider.txt")));
            }
          }
          return result;
        }
      }
      

  5.   

    如何操作Xml文件:http://www.blogcn.com/user63/rhfan2005/blog/25161802.html