C# 使用Textwriter从组合框写入URL
我目前正在尝试将输入到C# 使用Textwriter从组合框写入URL,c#,file,combobox,outlook,save,C#,File,Combobox,Outlook,Save,我目前正在尝试将输入到组合框中的URL(来自Outlook加载项)写入txt文件,但作为初学者,我真的不知道如何使用它 我没有任何代码片段可以在任何方面帮助您,所以我想我会保持简单,向您询问我在这件事上可以使用的一般方法。 非常感谢您的帮助,谢谢。这就是您想要的吗 string path=@"C:\Hello.txt"; TextWriter tsw = new StreamWriter(path,true); //Writing selected item of combobox t
组合框中的URL(来自Outlook加载项)写入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<string> lst = new List<string>();
foreach (var text in comboBox1.Items)
{
lst.Add((string)text);
}
File.WriteAllLines(@"c:\file.txt", lst.ToArray());
using (TextWriter TW = new StreamWriter(@"c:\file.txt", true))
{
foreach (var text in comboBox1.Items)
{
TW.WriteLine();
}
}