Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Textwriter从组合框写入URL_C#_File_Combobox_Outlook_Save - Fatal编程技术网

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();
                }
            }