using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Docs.Word;
using System.Text;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        // While trying to upload one or more files via HTTP a file uploading size limit that is set too low.
        // The most accessible way to change this limit is through the web.config configuration file.
        // Add the following line in the <system.web> tags: <httpRuntime maxRequestLength="102400" />.
        // This will increase the file upload size through HTTP to 100MB.

        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.ContentLength > 0)
        {
            Document doc = null;
            string fn = FileUpload1.PostedFile.FileName;
            Stream fstream = FileUpload1.PostedFile.InputStream;
            string ext = Path.GetExtension(fn).ToLower();


            // open word document
            switch (ext)
            {
                case ".doc":
                    doc = Document.ReadDOC(fstream);
                    break;
                case ".docx":
                    doc = Document.ReadDOCX(fstream);
                    break;
                case ".rtf":
                    doc = Document.ReadRTF(fstream);
                    break;
            }

            // Convert the word to the html document
            if (doc != null)
            {
                string HtmlContent = Encoding.Default.GetString(doc.WriteHTML().ToArray());
                DivContainer1.InnerHtml = HtmlContent;
            }
        }
    }

}