如何將列表框中的選定項目用作名稱對於新生成的文本文件? (Visual C#中)如何使用列表框中的選定項目作爲名稱對於新生成的文本文件
這裏是一段代碼:
string path = @"C:\\Public Key Pin\Test.txt";
if (!File.Exists(path))
{
File.Create(path);
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("The first line!");
}
}
else if (File.Exists(path))
{
MessageBox.Show("File with this path already exists.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
你的問題和代碼沒有多大意義。首先,您正在使用File.Create和File.CreateText兩次重新創建文件。其次,你使用的是什麼UI框架? WinForms,WPF?第三,您想在哪裏使用該值? – Christoph
謝謝,你實際上幫助我處理了另一個問題,因爲我沒有意識到它正在創建兩次文本文件。它給我一個錯誤,說另一個進程正在使用新創建的文件,它給了我一個錯誤,所以謝謝。 –
標題不需要任何標籤 – Muds