[英]Use Textwriter to write URLs from ComboBox
我目前正在尝试将输入到ComboBox
(来自Outlook加载项)的URL写入txt文件,但是作为我的初学者,我真的不知道该怎么做。
我没有任何代码片段可以为您提供任何帮助,因此我想通过询问您可以在此问题上使用的通用方法来简化它。 感谢您的所有帮助。
这是你想要的 ?
string path=@"C:\Hello.txt";
TextWriter tsw = new StreamWriter(path,true);
//Writing selected item of combobox to the file.
tsw.WriteLine(comboBox1.Items[this.comboBox1.SelectedIndex].ToString());
//Close the file.
tsw.Close();
尝试这个:
将组合项添加到List
,然后使用“ File
将其写入File
List<string> lst = new List<string>();
foreach (var text in comboBox1.Items)
{
lst.Add((string)text);
}
File.WriteAllLines(@"c:\file.txt", lst.ToArray());
使用TextWriter
using (TextWriter TW = new StreamWriter(@"c:\file.txt", true))
{
foreach (var text in comboBox1.Items)
{
TW.WriteLine();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.