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.NewLine
like:
_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.
Comments