私はメモ帳のクローンに取り組んでいますが、問題が発生しました。テキストボックス内のテキストを作成したファイルに書き込もうとすると、例外が発生します。
別のプロセスで使用されているため、プロセスはファイル 'C:\Users\opeyemi\Documents\b.txt' にアクセスできません。
以下は私が書いたコードです。次に何をすべきかについてアドバイスをいただければ幸いです。
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SaveFileDialog TextFile = new SaveFileDialog();
TextFile.ShowDialog();
// this is the path of the file i wish to save
string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),TextFile.FileName+".txt");
if (!System.IO.File.Exists(path))
{
System.IO.File.Create(path);
// i am trying to write the content of my textbox to the file i created
System.IO.StreamWriter textWriter = new System.IO.StreamWriter(path);
textWriter.Write(textEditor.Text);
textWriter.Close();
}
}