New Line Character is not shown in TextBox

Vishal

I have a form as shown in image below:

enter image description here

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:

enter image description here

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:

enter image description here

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:

enter image description here

Does anybody experienced the same problem in past?

Vishal

I just had to replace \n with Environment.NewLinelike:

_frmMsgDetails.MessageBody = dgvTemplates.SelectedRows[0].Cells[2].Value.ToString()
                                                .Replace("\n", Environment.NewLine);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related