Is there any method extension or smoething to include the Treelist nodes in XML SaveLayoutToStream.
I want this behaviour to preserve both data and layout, because i'm using an treelist as a "Favorites" and as a "Recent Items" implementation.
The goal is to save this to a sql databse. I already save the xml using the refered mrthos, but how can i include data in this method.
Is there any way to include the Treelist nodes in xml
Answers approved by DevExpress Support
Hi Silvio,
Attached is a small sample project that illustrates how to add datasource data to layout data. I have used LINQ To Xml. I have saved data to a file, but you can also save it to a stream as the XElement object supports different save methods.
Does this solution meet your requirements? If not, please feel free to reactivate ticket.
Thanks,
John.
Hi Silvio,
Thank you for your feedback. After data has been saved to a memory stream, the stream current position points to the end of the stream. Try to call the Seek(0, SeekOrigin.Begin) method for all memory streams before saving them to the database.
C#...
mainStreamFavoritos.Seek(0, SeekOrigin.Begin);
StreamReader readerFavoritos = new StreamReader(mainStreamFavoritos);
...
mainStreamMaisRecentes.Seek(0, SeekOrigin.Begin);
StreamReader readerMaisRecentes = new StreamReader(mainStreamMaisRecentes);
...
Please feel free to reactivate this ticket if you need any further assistance on this issue.
Thanks,
John.
Hi Silvio,
Thank you for your question. TreeList does not allow saving nodes in the layout xml data by default. However, you can save the nodes in particular xml data via ExportToXml or datasource methods (the WriteXml method for DataTable). In addition, you can store the nodes xml data as a separate file/record or include this data in the layout xml data manually using XmlDocument or LinqToXml.
Please feel free to reactivate this ticket if you need any further assistance on this issue.
Thanks,
John.
can u please send me a sample of saving nodes to xml and reading nodes to xml from the treelist.
Thanks in Advance…
Hi Silvio,
Please give me some additional time and I will provide you with an example.
Thanks,
John.
For instance I use this method to save treelist xml layout to database, how can i upgrade use the same method to save the nodes to database.
public static bool GravaConfiguracaoGrelha(TreeList grelha, String nomeGrelha)
{
try
{
MemoryStream stream = new MemoryStream();
grelha.SaveLayoutToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(stream);
Plat.PRIConnector.Executa("DELETE FROM TDU_ConfiguracaoGrelhas Where CDU_Grelha='" + nomeGrelha + "' and CDU_Utilizador='" + (Plat.PriLogin == null ? "" : Plat.PriLogin.Utilizador) + "'");
Plat.PRIConnector.Executa("INSERT INTO TDU_ConfiguracaoGrelhas(CDU_ID, CDU_Grelha, CDU_Config, CDU_Utilizador) VALUES ('" + Guid.NewGuid().ToString() + "', '" + nomeGrelha + "', '" + reader.ReadToEnd() + "', '" + (Plat.PriLogin == null ? "" : Plat.PriLogin.Utilizador) + "')");
}
catch (Exception)
{
return false;
}
return true;
}