1 Replies - 310 Views - Last Post: 28 June 2012 - 07:50 PM Rate Topic: -----

#1 vernekarsuraj32@yahoo.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-June 12

C# code to change .doc to .html

Posted 20 June 2012 - 02:41 PM

Hello Team,

I am working on convert .doc to .html. code works perfectly when i right click on the .aspx page and click on "View in browser" but the same code is not working when i use link or url like "http://10.9.39.65:8888"

i tried reinstalling the Microsoft office 2003 but still not working even try with different code still no success.

below is my code :

 string folder_to_save_in = @"C:\Inetpub\wwwroot\Pdf to HTML\Attachments\";
string filePath = folder_to_save_in + FileUpload1.FileName; // This bit does the actual file upload: 
FileUpload1.SaveAs(filePath);  
                    //Here we set up a WOrd Application... 
 Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
                    // Opening a Word doc requires many parameters, but we leave most of them blank... 
object o_nullobject = System.Reflection.Missing.Value; 
                    object o_filePath = filePath;
Microsoft.Office.Interop.Word.Document  doc = wordApplication.Documents.Open(ref o_filePath, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject);
                    // Here we save it in html format... 
                    // This assumes it was called "something.doc" 
                    string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", ".html");
                    object o_newfilename = newfilename;
                    object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
                    object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
                    object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
                    // Once again, we leave many of the parameters blank. 
                    // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd11/html/womthSaveAs1_HV05213080.asp 
                    // for full list of parameters. 
                    wordApplication.Activedocument.SaveAs(ref o_newfilename, ref o_format, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_encoding, ref o_nullobject, ref o_nullobject, ref o_endings, ref o_nullobject);
                    // Report success... Label1.Text = "Uploaded successfully!"; 
                    // Finally, close original... 
                   doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);

                    string path = newfilename;

                                        Response.Write("<script language='javascript'>alert('The file has been successfully uploaded !!!')</script>");
                }



                if (con != null)
                {
                    con.Close();
                }
                con = null;
                gdb = null;
                cmd = null;


            }





I am getting the below error :

System.Runtime.InteropServices.COMException (0x800A1066): Command failed at Microsoft.Office.Interop.Word.Documents.Open(Object& FileName, Object& ConfirmConversions, Object& ReadOnly, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Format, Object& Encoding, Object& Visible, Object& OpenAndRepair, Object& DocumentDirection, Object& NoEncodingDialog, Object& XMLTransform) at upload.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Pdf to HTML\upload.aspx.cs:line 59

This post has been edited by tlhIn`toq: 20 June 2012 - 02:45 PM
Reason for edit:: ending code tag as a slash [/code]


Is This A Good Question/Topic? 0
  • +

Replies To: C# code to change .doc to .html

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 2035
  • View blog
  • Posts: 6,060
  • Joined: 05-May 12

Re: C# code to change .doc to .html

Posted 28 June 2012 - 07:50 PM

Are you sure you are passing the correct filename to the Open call?

Also did you read this warning about using OLE Automation calls to Word from a (web) service: http://support.micro...-US;q257757#kb2

This post has been edited by Skydiver: 28 June 2012 - 07:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1