[C#] C#保存listbox中的数据到文本文件 →→→→→进入此内容的聊天室

来自 , 2019-09-29, 写在 C#, 查看 146 次.
URL http://www.code666.cn/view/7c9966af
  1. private void SaveLstToTxt(ListBox lst)
  2. {
  3.     sfd.Filter = "(*.txt)|*.txt";
  4.     if (sfd.ShowDialog() == DialogResult.OK)
  5.     {
  6.         string sPath = sfd.FileName;
  7.         FileStream fs = new FileStream(sPath, FileMode.Create);
  8.         StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
  9.         int iCount = lst.Items.Count - 1;
  10.         for (int i = 0; i <= iCount; i++)
  11.         {
  12.             sw.WriteLine(lst.Items[i].ToString());
  13.         }
  14.         sw.Flush();
  15.         sw.Close();
  16.         fs.Close();
  17.     }
  18. }
  19. //csharp/6994

回复 "C#保存listbox中的数据到文本文件"

这儿你可以回复上面这条便签

captcha