Essential Studio for Asp.Net | Demos

SHOWCASE SAMPLES
Showcase samples
    This sample illustrates how to convert Word document to EPUB file using Essential DocIO.

    Select Document


    Click the button to view the EPUB generated by Essential DocIO. Please note that EPUB viewer is required to view the resultant EPUB.


    <%@ Page  MasterPageFile="~/samplebrowser.master" Language="C#" AutoEventWireup="true" CodeBehind="DocToEPub.aspx.cs" Inherits="WebSampleBrowser.DocIO.DocToEPub" %>
    
    <asp:Content ID="Content3" ContentPlaceHolderID="ControlsSection" runat="server">
        This sample illustrates how to convert Word document to EPUB file using Essential DocIO.
        <div>
            <table width="850px" id="PanelTable" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td>
                        <div>
                            <div>
                                <br style="line-height: 10px" />
                            </div>
                            <b>Select Document</b>
                            <div>
                                <br style="line-height: 10px" />
                            </div>
                            <div>
                                <asp:FileUpload ID="fileUpload1" Width="385px" runat="server" />
                            </div>
                            <br />
                            <div>
                                <asp:Label Width="100%" Style="text-align: justify;" ID="label6" runat="server" Text="Click the button to view the EPUB generated by Essential DocIO. Please note that EPUB viewer is required to view the resultant EPUB."></asp:Label>
                            </div>
                            <br />
                            <div>
                                <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                        <td align="left">
                                            <asp:CheckBox runat="server" ID="chkBox1" Text="Embed Font Files" />
                                        </td>
                                    </tr>
                                    <tr>
                                    <td height="10px">
                                    </td>
                                </tr>
                                    <tr>
                                        <td align="left" >
                                            <asp:Button ID="btnDocToEPUB" Width="150px" Height="27px" runat="server" Text="Convert to EPUB"
                                                OnClick="btnDocToEPUB_Click" />
                                        </td>
                                    </tr>
                                </table>
                                <div>
                                    <br style="line-height: 10px" />
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <div>
                <asp:Label Width="100%" ForeColor="red" Style="text-align: justify;" ID="label1"
                    runat="server" Text=""></asp:Label>
            </div>
        </div>
    </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.DLS;
    using Syncfusion.DocIO;
    
    namespace WebSampleBrowser.DocIO
    {
        public partial class DocToEPub : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnDocToEPUB_Click(object sender, EventArgs e)
            {
                if (this.fileUpload1.HasFile)
                {
                    string ext = System.IO.Path.GetExtension(this.fileUpload1.PostedFile.FileName).ToLower();
                    if (ext == ".doc" || ext == ".docx")
                    {
                        //Convert the input word document to a EPub file
                        # region Convert Doc to EPub
                        Stream readFile = this.fileUpload1.PostedFile.InputStream;
                        try
                        {
                            WordDocument document = null;
                            if (ext == ".doc")
                                document = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Doc);
                            else if (ext == ".docx")
                                document = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Docx);
    
                            document.SaveOptions.EPubExportFont = this.chkBox1.Checked;
    
                            document.Save("Sample.epub", FormatType.EPub, Response, HttpContentDisposition.Attachment);
                            document.Close();
    
                            readFile.Close();
                            this.label1.Text = "";
    
                        }
                        catch (Exception)
                        {
                            this.label1.Text = "The input document could not be processed, Could you please email the document to support@syncfusion.com for troubleshooting";
                        }
    
                        # endregion
    
                    }
                    else
                    {
                        this.label1.Text = "Please choose a Word document to convert to EPub";
                    }
                }
    
                else
                {
                    this.label1.Text = "Browse a word document and then click the button to convert as a EPub document";
                }
            }
        }
    }