-6

I need to write text file from textbox on button's click event

after writing it I need to open same file

does not need to save that file while writing.

can anyone please give sample code?

EDIT

Actually you take me wrong ,I need to create temporary file , not in already existed file.. need to create , write and at same time it will be open to read.. is it possible ?

4

3 に答える 3

1

これはあなたが探しているものですか?

FileStream currentFileStream = null;//EDIT
string tempFilePath = Directory.GetCurrentDirectory() + "\\TEMP.txt";

if (!File.Exists(tempFilePath))
{
    currentFileStream = File.Create(tempFilePath);//creates temp text file
    currentFileStream.Close();//frees the file for editing/reading
}//if file does not already exist

File.WriteAllText(tempFilePath, textbox1.Text);//overwrites all text in temp file

//Inside your exit function:
if(File.Exists(tempFilePath)) File.Delete(tempFilePath);//delete temp file
于 2012-12-06T12:13:30.727 に答える
0

StreamWriterはテキストファイルを書き込みます。簡単で効率的なテキスト出力が可能になります。不要になったときにメモリから確実に削除されるように、usingステートメントに配置するのが最適です。いくつかのコンストラクターと多くのメソッドを提供します。

ここをクリック

Process.Start(ファイル)

于 2012-12-06T11:49:51.820 に答える
0

ファイルを再度開いた後、何をする必要がありますか?

簡単に言えば、テキストをファイルに書き込むことができます

System.IO.File.WriteAllText("path",textbox1.Text);

そして、次のコマンドでファイルを開くことができます:

system.IO.File.Open() // and the other variants .OpenText, OpenWrite
于 2012-12-06T11:52:29.413 に答える