private void 导出成功点击ToolStripMenuItem_Click(object sender, EventArgs e) { if (listCount.Items.Count == 0) { MessageBox.Show("列表为空!"); } else { List<string> list = new List<string>(); foreach (ListViewItem item in listCount.Items) { string temp = item.SubItems[2].Text; list.Add(temp); } Thread thexp = new Thread(() => export(list)) { IsBackground = true }; thexp.Start(); } } private void export(List<string> list) { string path = AppDomain.CurrentDomain.BaseDirectory + "url_" + Guid.NewGuid().ToString() + ".txt"; StringBuilder sb = new StringBuilder(); foreach (string tel in list) { sb.AppendLine(tel); } System.IO.File.WriteAllText(path, sb.ToString(), Encoding.UTF8); txtmsg.BeginInvoke(new Action(() => { string temp = "文件导出成功!文件地址:" + path; txtmsg.AppendText(temp.SetLog()); })); }
自己写的,并且测试可用,才发上来的!!!!
就是循环listview.items,然后,装到一个list<string>集合,然后。。。。
看代码吧。
时间: 2024-12-26 19:33:50