简体   繁体   中英

How to export the contents of the string or textbox to txt file that remains the same format (If string has 5 lines, txt file will has 5 lines)?

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
    FileInfo Myfile = new FileInfo(saveFileDialog1.FileName);
    StreamWriter wri = Myfile.CreateText();
    wri.WriteLine(Richtextbox.Text);
    wri.Close();
}

When I export to a text file, all the lines in richtextbox stick into one line. I donnot know how to keep file txt'content same as in richtextbox'content.

您可以使用SaveFile方法

Richtextbox.SaveFile(FileName, RichTextBoxStreamType.PlainText);
foreach (var line in Richtextbox.Lines)
{
    wri.WriteLine(line);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM