1

I need to convert the word document to HTML. I am able to do it with doc file

But when I use docx as input. I received an error

enter image description here

and here is my code

        public static string DocToHtml(string path)
        {
            try
            {
                //I used Microsoft Interop v12 because this doesn't give me the Access Violation Error.
                Microsoft.Office.Interop.Word.Application _App = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document _Doc = _App.Documents.Open(path);

                //Let's save the converted document to the temp folder
                string tempDocx = System.IO.Path.GetTempPath() + "_tempConvertedToHtml.html";
                object _DocxFileName = tempDocx;
                object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML;
                _Doc.Convert();
                _Doc.SaveAs(ref _DocxFileName, ref FileFormat);


                //Close the Word interface
                _Doc.Close();
                _App.Quit();

                path = tempDocx;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            return path;
        }
1
  • What line gives you the error? Apr 24, 2017 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.