Click here to Skip to main content
14,635,443 members
Rate this:
Please Sign up or sign in to vote.
I am trying to convert word document to html in my asp.net applicaiton. it working fine in debug mode after i publish an hosted it is not working and i am getting the error "This command is not available because no document is open."

Below is the code i am using

if (File.Exists(strFilePath))
                {
                    string strFileName = Path.GetFileName(strFilePath);
                    string strExt = Path.GetExtension(strFileName);
                    strPathToUpload = Server.MapPath("Files");
                    strPathToConvert = Server.MapPath("Files");
                    object FileName = strPathToUpload + "\\" + strFileName;
                    object FileToSave = strPathToConvert + "\\JobOpening.htm";
                    if (strExt.ToUpper().Equals(".DOC") || strExt.ToUpper().Equals(".DOCX"))
                    {
                        byte[] file = null;
                        FileInfo tempInfo = new FileInfo(strFilePath);
                        if (tempInfo.Exists)
                        {
                            FileStream fStream = tempInfo.OpenRead();
                            file = GetBytesFromStream(fStream);
                            fStream.Close();
                            fStream.Dispose();
                            WriteToFile(FileName.ToString(), ref file);
                            text = FileName.ToString();
                            objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
                            objWord.Visible = false;
                            Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
                            oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                        }
                    }
                }


Please any one help me to solve this issue.

Thanks in advance.
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
hari111r 14-Feb-14 1:06am
   
Thanks for the links,
Have a doubt, is it possible to convert word document to html using Open XML SDK with same format(font,color,font size).
Can you please help me by providing any link for that.
I try to solve this issue from past two days.

Thanks in advance.
   
There is no one-to-one correspondence. You can only make HTML look like your source document, more or less.
Actually, you inputs comes in two parts: one is the DOCX file, another input is some set of mapping rules you want to build to meet some requirements. It is up to you how you formulate them. This is actually a very usual feature of some sites, such as job-search sites where users submit resume documents. I don't know any particular source code samples, but I'm sure you can find something...
—SA
hari111r 18-Feb-14 5:18am
   
Hi,
I am still not able to find solution to convert doc to html with same formating in asp.net even using open xml sdk. can you please help me to solve the introp issue or any link to convert doc to html or atleast i want to embed doc in asp.net page.
Sergey Alexandrovich Kryukov 18-Feb-14 11:29am
   
I don't have any links. no more than you could have. The remaining problem is not a problem which can be solved by one more expert advice; this is just the work to be done, and the work which requires considerable time. As you did not explain where your difficulties are, I don't know what to add...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100