I have a huge content in a string variable and I want to write that content to a text file using stream writer. But the stream writer is truncating the text and not writing the whole content to file. Why?
using (StreamWriter sw = new StreamWriter(completeFilePath))
{
sw.Write(txt);
}
After Write, use Flush method to clear buffer.
sw.Write(Html);
sw.Flush();
If the size is too large,
using (StreamWriter sw = new StreamWriter(completeFilePath))
{
sw.Write(txt);
//just to make sure the stream writer flushes the command
sw.Flush();
}
If the size isn't that large, I suggest to use File.WriteAllText method
//no need to Open or Close anything
File.WriteAllText(Path, txt);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With