I have a form as shown in image below:

Now, When user clicks on Save As Template, I save the text of the textbox in XML File. The Code I use to save this text in XML File is :
public static void SaveTemplate(string Message)
{
XDocument xmlDocument = XDocument.Load(templatesPath);
xmlDocument.Element("Templates").Add(
new XElement("Template", new XAttribute("Id", xmlDocument.Root.Elements("Template").LastOrDefault() != null ? int.Parse(xmlDocument.Root.Elements("Template").LastOrDefault().Attribute("Id").Value) + 1 : 1),
new XElement("Body", Message)));
xmlDocument.Save(templatesPath);
}
The text saved in XML file looks like:

After that User may do whatever he wants. When User runs my application again, the textbox is empty. So, he will click on Load Template Button. At that time the text is shown in datagridview:

Now, User clicks on Select Template and the text from DataGridViewCell is copied to textbox again. But the text does not contain new lines. Look at the image below:

Does anybody experienced the same problem in past?
I just had to replace \n with Environment.NewLinelike:
_frmMsgDetails.MessageBody = dgvTemplates.SelectedRows[0].Cells[2].Value.ToString()
.Replace("\n", Environment.NewLine);
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