Skip to main content

Save to File

You can use ASP.NET methods to save the ASPxHtmlEditor’s content to a file (a text file, HTML file, and so on).

<div id="Div1">Your name:</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<div id="Div2">Your message:</div>
<dx:ASPxHtmlEditor ID="ASPxHtmlEditor1" runat="server">
</dx:ASPxHtmlEditor>
<asp:Button ID="Button1" runat="server" Text="Save to File" onclick="Button1_Click" />
public partial class _Default : System.Web.UI.Page {
    protected void Page_Load(object sender, EventArgs e) {
    }
    protected void Button1_Click(object sender, EventArgs e) {
        string myHtml = ASPxHtmlEditor1.Html.ToString();
        string fileName = TextBox1.Text + DateTime.Today.Date.ToShortDateString() + ".txt";
        string fullFileName = Request.MapPath("Files/" + fileName);
        StreamWriter streamWriter = 
            new StreamWriter(new FileStream(fullFileName, FileMode.Create, FileAccess.Write));
        streamWriter.Write(myHtml);
        streamWriter.Close();
    }
}