Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sir,
How to Save data from ajax control toolkit editor to Xml.
bellow is my code for editor..I want to save this data to xml.Iam first time in xml.
generates error like
XML
System.Xml.XmlException: Data at the root level is invalid. Line 3, position 19.
xmldoc.Load(Server.MapPath("/myajaxEditor.xml"));
if any one knows the answer please help me...
<pre lang="xml">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;  CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt;
&lt;%@ Register Assembly=&quot;AjaxControlToolkit&quot; Namespace=&quot;AjaxControlToolkit.HTMLEditor&quot;
    TagPrefix=&quot;cc1&quot; %&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot;&gt;
    &lt;/asp:ScriptManager&gt;
    &lt;div&gt;
        &lt;cc1:Editor ID=&quot;Editor1&quot; runat=&quot;server&quot; Width=&quot;600px&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
        &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; onclick=&quot;Button1_Click&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
        &lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;Label&quot;&gt;&lt;/asp:Label&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(Server.MapPath("myajaxEditor.xml"));
        XmlElement parentelement = xmldoc.CreateElement(" CallDetails");
        parentelement.InnerText = Editor1.Content;<pre lang="c#"></pre>
Posted
Updated 2-May-14 22:59pm
v3

try below
C#
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
xml.LoadXML(myajaxEditor.Content.replace(" ","")); 
xml.Save(Server.MapPath("myajaxEditor.xml"));
 
Share this answer
 
XML
<%@ Page Language="C#" Debug="true" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <cc1:Editor ID="Editor1" runat="server" Width="600px" /><br /><br />
        <asp:Button ID="Button1" runat="server" Text="Save Data" onclick="Button1_Click" /><br /><br />
         <asp:Button ID="Button2" runat="server" Text="Get Data" OnClick="Button2_Click" />


    </div>
    </form>

</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e) //for insert in to xml file
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(Server.MapPath("~/xmlfile/test.xml"));
        XmlElement parentelement = xmldoc.CreateElement("Details");
        XmlElement name = xmldoc.CreateElement("Callinformations");
        name.InnerText = Editor1.Content;
        parentelement.AppendChild(name);
        xmldoc.DocumentElement.AppendChild(parentelement);
        xmldoc.Save(Server.MapPath("~/xmlfile/test.xml"));
        Editor1.Content = "";
       
    }
    protected void Button2_Click(object sender, EventArgs e) //get data from xml file
    {
        XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("~/xmlfile/test.xml"));
        DataSet ds = new DataSet();
        ds.ReadXml(xmlreader);
        DataTable dt = ds.Tables[0];
        for (int i = 1; i < dt.Rows.Count; i++)
        {

            Editor1.Content = dt.Rows[i]["Callinformations"].ToString();
        }
        
    }
   
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900