Essential Studio for Asp.Net | Demos

SHOWCASE SAMPLES
Showcase samples
    Import and Export
    <%@ Page Language="C#" Title="RichTextEditor-Import and Export-ASP.NET-SYNCFUSION" AutoEventWireup="true" MasterPageFile="~/Samplebrowser.Master" CodeBehind="ImportExport.aspx.cs" Inherits="WebSampleBrowser.RichTextEditor.ImportExport" %>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="SampleHeading" runat="server">
        Import and Export 
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="ControlsSection" runat="server">
            <ej:RTE ID="ImportExportSample" Width="100%" Height="100%"  runat="server" MinWidth="200px" >
                <RTEContent>
                    <p><b>Description:</b></p>
            <p>The Rich Text Editor (RTE) control is an easy to render in
            client side. Customer easy to edit the contents and get the HTML content for
            the displayed content. A rich text editor control provides users with a toolbar
            that helps them to apply rich text formats to the text entered in the text
            area. </p>
           <p><b>Functional
            Specifications/Requirements:</b></p>
            <ol><li><p>Provide
            the tool bar support, it’s also customizable.</p></li><li><p>Options
            to get the HTML elements with styles.</p></li><li><p>Support
            to insert image from a defined path.</p></li><li><p>Footer
            elements and styles(tag / Element information , Action button (Upload, Cancel))</p></li><li><p>Re-size
            the editor support.</p></li><li><p>Provide
            efficient public methods and client side events.</p></li><li><p>Keyboard
            navigation support.</p></li></ol>
            </RTEContent>
            <ImportSettings Url="Import.ashx" />
            <ExportToWordSettings Url="ImportExport.aspx/ExportToWord" FileName="WordExport" />
            <ExportToPdfSettings Url="ImportExport.aspx/ExportToPDF" FileName="PdfExport" />
            <Tools
                ImportExport="import,wordExport,pdfExport">
            </Tools>
        </ej:RTE>
    </asp:Content>
    
    <asp:Content runat="server" ContentPlaceHolderID="StyleSection" ID="content1">
        <style>
            #LayoutSection_ControlsSection_DefaultRTE_wrapper {
                min-width: 200px !important;
            }
        </style>
    </asp:Content>
    
    
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    using Syncfusion.DocIO;
    using Syncfusion.DocIO.DLS;
    using System.Web.Http;
    using System.Collections.Generic;
    using Syncfusion.EJ.Export;
    using Syncfusion.DocToPDFConverter;
    using Syncfusion.Pdf;
    
    namespace WebSampleBrowser.RichTextEditor
    {
        public partial class ImportExport : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string exportDoc = "ImportExport.aspx/ExportToWord",  exportPdf = "ImportExport.aspx/ExportToPDF";
                string RequestURL = HttpContext.Current.Request.Url.ToString();           
                if (RequestURL.Contains(exportDoc)) ExportToWord();
                else if (RequestURL.Contains(exportPdf)) ExportToPDF();
            }
          
            public void ExportToWord()
            {
    
                string RTEID = HttpContext.Current.Request.QueryString["rteid"];
                string FileName = HttpContext.Current.Request.Params[RTEID + "_inputFile"];
                string htmlText = HttpContext.Current.Request.Params[RTEID + "_inputVal"];
                WordDocument document = GetDocument(htmlText);
                document.Save(FileName + ".docx", FormatType.Docx, HttpContext.Current.Response, HttpContentDisposition.Attachment);
            }
    
         
            public void ExportToPDF()
            {
                string RTEID = HttpContext.Current.Request.QueryString["rteid"];
                string FileName = HttpContext.Current.Request.Params[RTEID + "_inputFile"];
                string htmlText = HttpContext.Current.Request.Params[RTEID + "_inputVal"];
                WordDocument document = GetDocument(htmlText);
                DocToPDFConverter converter = new DocToPDFConverter();
                PdfDocument pdfDocument = converter.ConvertToPDF(document);
                pdfDocument.Save(FileName + ".pdf", HttpContext.Current.Response, HttpReadType.Save);
            }
    
    
            public  WordDocument GetDocument(string htmlText)
            {
                WordDocument document = null;
                MemoryStream stream = new MemoryStream();
                StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Default);
                htmlText = htmlText.Replace("\"", "'");
                XmlConversion XmlText = new XmlConversion(htmlText);
                XhtmlConversion XhtmlText = new XhtmlConversion(XmlText);
                writer.Write(XhtmlText.ToString());
                writer.Flush();
                stream.Position = 0;
                document = new WordDocument(stream, FormatType.Html, XHTMLValidationType.None);
                return document;
            }
        }
    }