Essential Studio for Asp.Net | Demos

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

    Select Document


    Click the button to view the resultant ODT document generated by Essential DocIO.


    <%@ Page MasterPageFile="~/samplebrowser.master" Language="C#" AutoEventWireup="true" CodeBehind="DocToODT.aspx.cs" Inherits="WebSampleBrowser.DocIO.DocToODT" %>
    
    <asp:Content ID="Content3" ContentPlaceHolderID="ControlsSection" runat="server">
        This sample illustrates how to convert Word document to ODT using Essential DocIO.
        <div>
            <table width="650px" 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 resultant ODT document generated by Essential DocIO."></asp:Label>
                            </div>
                            <br />
                            <div>
                                <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                    <tr>
                                        <td align="left">
                                            <asp:Button ID="btnDocToODT" Width="150px" Height="27px" runat="server" Text="Convert to ODT"
                                                OnClick="btnDocToODT_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.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Syncfusion.DocIO;
    using Syncfusion.DocIO.DLS;
    using System.IO;
    
    namespace WebSampleBrowser.DocIO
    {
        public partial class DocToODT : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void btnDocToODT_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 ODT file
                        # region Convert Doc to ODT
                        Stream readFile = this.FileUpload1.PostedFile.InputStream;
                        try
                        {
                            WordDocument wordDoc = null;
                            if (ext == ".doc")
                                wordDoc = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Doc);
                            else if (ext == ".docx")
                                wordDoc = new WordDocument(readFile, Syncfusion.DocIO.FormatType.Docx);
    
                            //Save the odt file 
                            wordDoc.Save("DocToODT.odt", FormatType.Odt, Response, HttpContentDisposition.Attachment);
    
                            readFile.Close();
                            this.label1.Text = "";
    
                        }
                        catch (Exception e1)
                        {
                            this.label1.Text = e1.Message;
                        }
    
                        # endregion
    
                    }
                    else
                    {
                        this.label1.Text = "Please choose doc or docx file to convert to ODT";
                    }
                }
    
                else
                {
                    this.label1.Text = "Browse a word document and then click the button to convert as a ODT document";
                }
            }
        }
    }