Last post Dec 03, 2015 05:11 AM by wim sturkenboom
Dec 02, 2015 09:42 AM|Melody_xxxx|LINK
//write filename to txt
FileStream fs = new FileStream(newPath + "\\FileInfo.txt", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
MessageBox.Show(this, "GetSuccess", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
The MessageBox is show and when I debug txt has value.But when I open the file "FileInfo.txt" , I found it is empty?
Dec 02, 2015 09:48 AM|Nan Yu|LINK
Hi Melody ,
Firstlly ,since you are writing a winform application , please post to
winform forum for help .
Secondly , you need to use StreamWriter.Close Method () to ensure that all data is correctly written out to the underlying stream . Please try below code:
Hope it helps.
Dec 03, 2015 05:11 AM|wim sturkenboom|LINK
You will be better off using 'using'; you will run out of resources quickly if you don't cleanup after yourself ;-)
using (FileStream fs = new FileStream(newPath + "\\FileInfo.txt", FileMode.OpenOrCreate))
using (StreamWriter sw = new StreamWriter(fs))
This will properly close and cleanup all resources that you use.