none
Microsoft.Office.Interop.Word.Application.Documents.Open Issue with filename RRS feed

  • Question

  • Hi,

    I have a word document in hosted website in the path "Root\documents\sample.doc".Now i need to send it as pdf to the client for that i used the fallowing code

    object Unknown = Type.Missing;
    object ReadOnly;object Source = @"C:\site1\documents\Summary.doc";
    object Target = @"C:\site1\documents\Summary.pdf";
    object format=Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
       Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
       Microsoft.Office.Interop.Word.Document doc = WordApp.Documents.Open(ref Source, ref Unknown, ref ReadOnly,
           ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
    
       WordApp.ActiveDocument.SaveAs2(ref Target, ref format,
             ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown,
           ref Unknown, ref Unknown, ref Unknown);
       Response.TransmitFile(Target.ToString());
    

    When i Excute this solution from visual studio it is working fine

    but when i hosted as website "Microsoft.Office.Interop.Word.Application.Documents.Open" could not open the file in the specified path and it is returning the document as null

    Can anybody provide me the solution for this issue.

    Thanks in Advance.


    • Moved by William Zhou CHN Friday, July 22, 2011 5:30 AM Coding for Developer (From:Word IT Pro Discussions)
    Wednesday, July 20, 2011 10:57 AM

Answers

All replies

  • Hi CRM40,

    As for the problem, please see whether this article can help you:

    http://www.shotdev.com/asp/asp-word/asp-config-word/

    Actually, Microsoft does not recommond and support server side automation of Office application, there may exist a lot of unexpect behavior. For more details, please refer to this kb article:http://support.microsoft.com/kb/257757

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    So, you may need to consider to use open xml technology and docx file format.

    Thank you for your understanding and wish you a nice day.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, July 26, 2011 8:18 AM
  • Hi Bruce Song, Thanks for Reply.

    Actually i am using windows server 2008 r2 with IIS 7 and microsoft office 2010,I was not able to find the "Microsoft word Document" under DCOM Config section of Component services as you provided from the link.

    I located word application at "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" and has given full permission to iis_users even though the result same.

    can you please guide me briefly how to solve this issue.

    If it possible to create word document from html and then convert into pdf or create pdf from html directly with open xml technology can you please provide me the solution to achieve it.

    Thanks in advance.

    Tuesday, July 26, 2011 1:06 PM
  • Hi Crm40,

    If you want to create document from html and keep the format just as the html page, you need to transform the html tag to be openxml tag. I know a 3rd part tool which can convert html page to plain open xml document:http://notesforhtml2openxml.codeplex.com/

    And the best way to convert Open xml to PDF is to use word automation services:

    http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/0ca9dd54-4340-49c9-a9b2-3e78cf4c4c1b

    Hope this can give you some hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 27, 2011 7:39 AM
  • Hi Bruce Song,

    The suggested solution is looking good but not fit to my situation. Converting html to Openxml document is fine and then convert open xml to pdf need word automation services comes by Sharepoint server installation.Unfortunately my windows server 2008 r2 was not installed by sharepoint server.

    Can you please provide me any other solution for converting html to pdf using any API .net libraries automatically.


    I tried to use iTextSharp free .Net pdf generator.It is able to generate pdf but couldnt formate it as required.Let me know one thing that can i use these type of third party tools in my production server without any risk.

    Thanks in advance.

    Wednesday, July 27, 2011 1:20 PM
  • Dear CRM40,

    You can try this:

    Aspose.Words for .NET

    http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx

    and the price is reasonable.

    Hope this helps.

    Regards,


    Be happy.

    • Proposed as answer by Mike_HelpYou Tuesday, August 2, 2011 3:51 AM
    • Marked as answer by Bruce Song Tuesday, August 9, 2011 7:24 AM
    Thursday, July 28, 2011 3:31 AM
  • Hai Mike,

    Can i use itextsharp .net pdf generator as free .net library  in my production server without any risk.

    Thanks in advance.

    Thursday, July 28, 2011 5:17 AM
  • Dear CRM40,

    It is not free and it can let us try free for 30 days. I think the price is reasonable and you can get the support from them.

    Hope this helps.

    Regards,


    Be happy.
    Monday, August 1, 2011 7:09 AM
  • Dear CRM40,

    Would you like to choose the  Aspose.Words for .NET? Does this meet with your requirement?

    Hope this helps.

    Best Regards,


    Be happy.
    Wednesday, August 3, 2011 6:47 AM