Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing content of text file using C#

Tags:

c#

.net

file

text

How can I clear the content of a text file using C# ?

like image 542
Morano88 Avatar asked Apr 23 '10 00:04

Morano88


People also ask

How do you clear the contents of a text file in C++?

If you simply open the file for writing with the truncate-option, you'll delete the content.

How do you delete text in a file?

Open the file with your text editor and press End. Highlight and PgUp to delete the remaining bytes that don't belong (usually recognizable by ASCII garbage characters).

How do I change the contents of a file in C?

If you switch between input and output on a file opened for update mode, you must use a file positioning operation ( fseek() , rewind() , nominally fsetpos() ) between reading and writing; and you must use a positioning operation or fflush() between writing and reading.


1 Answers

File.WriteAllText(path, String.Empty); 

Alternatively,

File.Create(path).Close(); 
like image 98
SLaks Avatar answered Oct 08 '22 21:10

SLaks