How can I clear the content of a text file using C# ?
You can use always stream writer.It will erase old data and append new one each time.
using (StreamWriter sw = new StreamWriter(filePath)) { getNumberOfControls(frm1,sw); }