You can save and load content to HTML/Database.
In this topic, you will learn how to save and load content.
To save and load content to HTML
-
To save content to file, use the provided SaveContentToFile server side method.
There are 3 parameter for this method "fileName", "sectionName" and
"docType". "sectionName" parameter is used to save the content from a specific
editor section, where as "docType" is used to save the editor's content including
html declaration (by default there is no html declaration). There are 2 options
for "DocType", HTMLDocType and XHTMLDocType.
-
Place the following code in button click event to save content to HTML file.
protected void Button1_Click(object sender, EventArgs e)
{
WebTextEditor1.SaveContentToFile(Server.MapPath("./SampleHtml/SavedFile.html"), WebTextEditorHtmlDocType.XHTMLDocType, "Title Name", true);
}
|
-
To load content from file, please use LoadContentFromFile server side method.
There are several parameters provided in this method such as "fileName",
"sectionName" , "isCompleteHTML". "sectionName" parameter is used
to load from file to specific section of editor (multiple section), "isCompleteHTML"
parameter should be set to true if loaded file is a full/complete html file.
- Place the following code in button click event to load content from HTML file.
protected void Button1_Click(object sender, EventArgs e)
{
WebTextEditor1.LoadContentFromFile(Server.MapPath("./SampleHtml/Product Overview.html"), true);
}
|
- Run the project.
To save and load content to Database
- Bind Editor(Editor.mdb) database to AccessDataSource control.
- Place the following code in button click event to save content to database.
protected void Button1_Click(object sender, EventArgs e)
{
AccessDataSource1.UpdateParameters["ID"].DefaultValue = "1";
AccessDataSource1.UpdateParameters["EditorName"].DefaultValue = "Budianto";
AccessDataSource1.UpdateParameters["ScriptInformation"].DefaultValue = TextEditor1.RootTextEditor.Content;
AccessDataSource1.Update();
}
|
- Place the following code in button click event to load content from database.
protected void Button1_Click(object sender, EventArgs e)
{
DataView data = (DataView)AccessDataSource1.Select(DataSourceSelectArguments.Empty);
TextEditor1.RootTextEditor.Content = data.Table.Rows[0]["ScriptInformation"].ToString();
}
|
- Run the project.