Friday, 9 August 2013

i need to write data to a file in c# but somehow it shows success but the file is empty

i need to write data to a file in c# but somehow it shows success but the
file is empty

Hello This is the code i am trying : If the file existes , append to that
file else create a new one . I need to write data line by line
FileExists = File.Exists(NewFileName);
if (FileExists = false)
{
using (fs =new FileStream(NewFileName,
FileMode.Create))
{
sw = new StreamWriter(fs);
MessageBox.Show(Record);
sw.WriteLine(Record);
fs.Close();
}
}
else
{
using (fd = new FileStream(NewFileName,
FileMode.Append))
{
sw = new StreamWriter(fd);
MessageBox.Show(Record);
sw.WriteLine(Record,true);
}
}
}

No comments:

Post a Comment