locked
convert word document into html RRS feed

  • Question

  • Hi all,
     I am developing an email application that provides a facility to import a word document to  web browser 
    control . The word document(*.doc) has text with images. Web browser control can be populated with 
    Html document . I am able to load all doc contents(with images)  into web browser control. After sending mail ,at the receiving end the images are not displayed  .only text is viewable.
    here is the code snippet 

    private void btnImport_Click(object sender, EventArgs e)

    {

    string  strfileName;

    OpenFileDialog OpenDialog = new OpenFileDialog();

    OpenDialog.FileName = "*.doc"; //prepare open file dialog to only search for doc files

    OpenDialog.Title = "Open a doc file"; // sets Title of open dialog

    OpenDialog.Filter = "Document Files | *.doc"; //sets file of type

    if (OpenDialog.ShowDialog() == DialogResult.OK)

    {

      strfileName = OpenDialog.FileName.ToString(); /*assigning  file path of doc file to a string */
     

    strMsgBody =  ReadDocAsHTML(strfileName);/*calling a method to change doc file into html */ 

    int index = strMsgBody[0].IndexOf("<html");

    /*===Removing all contents before '<html' tag =====*/

    strMsgBody[0] = strMsgBody[0].Remove(0, index);

     wbBody.DocumentText = strMsgBody[0]; /* webbrowser control name -wbBody */

     }

    public string[] ReadDocAsHTML(string strFile)

    {
    string[] text = new string[2];

    Microsoft.Office.Interop.Word.ApplicationClass wordApplication;

    wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();

    object o_null = System.Reflection.Missing.Value;
    object o_filePath = strFile;

    Microsoft.Office.Interop.Word.Document doc;
    doc = wordApplication.Documents.Open(ref o_filePath,ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null, ref o_null,ref o_null, ref o_null, ref o_null, ref o_null, ref o_null);

    wordApplication.ActiveWindow.Selection.WholeStory();

    wordApplication.ActiveWindow.Selection.Copy();

    IDataObject data = Clipboard.GetDataObject();

    wordApplication.Quit(ref o_null, ref o_null, ref o_null);

    System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApplication);

    text[0] = data.GetData(DataFormats.Html).ToString();

    text[1] = data.GetData(DataFormats.Text).ToString();

    text[0] = Regex.Replace(text[0], @"[^\u0000-\u007F]", "");

     

    return text;

    }


    Now using smtpClient i send mail .. but the images are not viewable at receiving end ...
    I appreciate ur help.......
    Thanks ............











    Wednesday, January 7, 2009 5:29 AM

Answers