locked
Word to Html Conversion in Server Side RRS feed

  • Question

  • Sir,

    I'm in project where I have to convert a doc file into html file & then read the html text to paste the same in a Email body. The main problem of this project is to convert the doc file into html file in Server Side only. And there is no issue if I execute the same code in client side.

    I'm using Microsoft.Office.Interop.Word for this conversion task. I have given my code below.... (May be you're not familiar with this type of programming Language).

    FileName :='D:\New\'+'Document.docx'; // Server Side file Path

    //Doc to Html-
    WordApplication :=WordApplication.ApplicationClass;
    WordApplication.Visible:=FALSE;
    WordDocument :=WordHelper.CallOpen(WordApplication,FileName,FALSE,FALSE);
    FileName2 := 'D:\New2\'+DELCHR(FORMAT(CURRENTDATETIME),'=','\/:*?"<>| ');
    WordHelper.CallSaveAsFormat(WordDocument,FileName2,WordSaveFormat.wdFormatHTML);
    WordHelper.CallClose(WordDocument,FALSE);
    WordHelper.CallQuit(WordApplication,FALSE); 

    But WordHelper.CallOpen is unable open the file & arises an error message for next function call ...

    Word.WordHelper.CallSaveAsFormat failed with this message: Value cannot be null. Parameter name: document

    Is there any way to overcome this issue ? Kindly inform if there is any.

    Subrata Bauri



    Friday, April 26, 2019 7:24 AM

All replies

  • I would recommend using the Open Xml Sdk for this instead of automating word.

    https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/ff628051(v=office.14)

    Friday, April 26, 2019 8:39 AM
  • Yup, people writing server side application should definately use OpenXMLSdk over Office Automation. For one thing, even if you disabled prompt (set .DisplayAlerts to wdAlertsNone), it doesn't disable all code paths that can lead to modal dialog, and that can freeze your application.

    However OpenXMLSdk does not enable you to do Word file to HTML conversion, so this has to be done with some 3rd party libraries.

    =======

    Btw, your WordHelper is custom made class that we don't have information about what parameter does it expect. The notation of "missing parameter" on "document" seems to suggest that you forgot to pass WordApplication.ActiveDocument to that method.


    • Edited by cheong00 Monday, April 29, 2019 1:34 AM
    Monday, April 29, 2019 1:32 AM
  • Hi navuser1,

    Since your question is more related to Microsoft.Office.Interop.Word, you could post a new thread in Word for Developers.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev&filter=alltypes&sort=lastpostdesc

    Best Regards,

    Wendy



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 1, 2019 6:22 AM
  • Thanks a lot to Ken Tucker, cheong00 & Wendy Zang for your time & consideration.

    As I was in a hurry, so I have created a custom library with the help of 3rd party extension & solved the issue for the urgent basis.

    I will obviously go thru your suggestions very soon for the concrete solution.

    Rgds,

    Subrata Bauri



    • Edited by navuser1 Thursday, May 2, 2019 12:27 PM
    Thursday, May 2, 2019 12:09 PM
  • I have created a DotNet Library(A) with the help of 3rd Party Library(B) and I have faced the following error message from my code (where custom library is used)...

    A call to AcxiomXmlToHtml.AcxiomApplication.ConvertXml2html failed with this message: Could not load file or assembly 'GemBox.Spreadsheet, Version=43.0.35.1115, Culture=neutral, PublicKeyToken=b1b72c69714d4847' or one of its dependencies. The system cannot find the file specified.

    GemBox is the 3rd Party Library which I used in my own library creation. I don't want any dependency error from my own Library at all. The error message disappear when I installe the GemBox software in the system where the code is executed.

    How do I achieve that without the GemBox installation ?

    Kindly reply.

     

    • Edited by navuser1 Monday, May 6, 2019 11:41 AM
    Monday, May 6, 2019 11:39 AM
  • We have no information for the library you choose to use, how could you expect us able to tell you how to get rid of a dependency?

    You're advised to consult with your colleague or the library's provider directly.

    Tuesday, May 7, 2019 1:17 AM
  • I have created a .dll which have reference of other .dll from 3rd Party. It's working fine where both the .dll are exist/deployed. 

    Is there any way that the 3rd Party could be included in my custom .dll & I could only depend on my custom .dll to be used without any 3rd Party .dll dependency ?

    I will share my code if require. 

    Thank you,

    Subrata

     
    Tuesday, May 7, 2019 6:07 AM
  • In short, no.

    Unlike C++ where the vendor may choose to provide .lib file for you to static link their code in your binary, C# only supports the use of DLL for extenal projects, and DLL must be present to provide their function.

    To remove the need of that 3rd party library you'll need to write your own code to replace them.

    I'll also note that although there are applications that allows you to merge multiple assemblies into one, I have no idea whether it'll work for that particular library, and using them on libraries that you don't own can have legal implications. (Most licensing does not allow you to modify their assembly and ship them, or may require you to opensource your code if you do this)




    • Edited by cheong00 Tuesday, May 7, 2019 8:12 AM
    Tuesday, May 7, 2019 7:50 AM
  • Thank you.
    Thursday, May 9, 2019 6:22 AM