0

I looked all over Google, but could not find anything other than:

File.WriteAllLines();

It does not work, it just appends it.
Cheers.

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Lusiphur
1
FileStream f = File.Open(@"D:\TestData.txt", FileMode.Create);
f.Close();

Edited by Momerath: n/a

Votes + Comments
n/a
0
FileStream f = File.Open(@"D:\TestData.txt", FileMode.Create);
f.Close();

Momerath's method will do what you require if all you need is the file to be emptied.

Essentially what it accomplishes is that it will open the file in create mode which makes any existing file with the same name be deleted and replaced with the new file. Further, the code closes the stream without adding to the new file leaving you with an empty new file.

If, on the other hand, you require some of the details of the file to remain then you will need to first read the details into a variable, prune off the unnecessary bits, then create the new same-name file and insert the trimmed contents.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.