locked
Merging Multiple Word documents (.doc) in C# RRS feed

  • Question

  • User910499198 posted

    Hi,

    I'm trying to merge multiple word documents into one, in VS 2010 C# with the help of Microsoft.Office.Interop.Word.dll.

    While executing below piece of code, it is throwing error:

    Code:

    objApp = new ApplicationClass();
                object objOrgDoc = strOrgDoc;
    
                Document objDocLast = null;
                Document objDocBeforeLast = null;
    
                objDocLast = objApp.Documents.Open(
                  ref objOrgDoc,    //FileName
                  ref objMissing,   //ConfirmVersions
                  ref objMissing,   //ReadOnly
                  ref objMissing,   //AddToRecentFiles
                  ref objMissing,   //PasswordDocument
                  ref objMissing,   //PasswordTemplate
                  ref objMissing,   //Revert
                  ref objMissing,   //WritePasswordDocument
                  ref objMissing,   //WritePasswordTemplate
                  ref objMissing,   //Format
                  ref objMissing,   //Enconding
                  ref objMissing,   //Visible
                  ref objMissing,   //OpenAndRepair
                  ref objMissing,   //DocumentDirection
                  ref objMissing,   //NoEncodingDialog
                  ref objMissing    //XMLTransform
                  );
    

    Error:

    Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    Looking for a solution to it.

    Thanks!



    Monday, June 24, 2013 9:52 AM

Answers

All replies

  • User-718146471 posted

    Where are you getting this error? Did you create the reference to that DLL? Is that DLL in your BIN folder?

    Monday, June 24, 2013 12:15 PM
  • User910499198 posted
    objDocLast = objApp.Documents.Open(

    The above line throws me error. Yes, I did reference the DLL and its in my BIN folder.

    Tuesday, June 25, 2013 9:20 AM
  • User-718146471 posted
    What I mean by where is are you seeing this in your dev environment or on your production?
    Tuesday, June 25, 2013 9:24 AM
  • User-718146471 posted

    It looks like you got the code from here: http://www.codeproject.com/Articles/7582/Merging-Word-Documents-with-C 

    Tuesday, June 25, 2013 9:28 AM
  • User-718146471 posted

    By reading that article, it looks like this guy requires MS Word 2003 to work for starters.

    Tuesday, June 25, 2013 9:32 AM
  • User910499198 posted

    Well, to answer your above asked questions:

    1. I'm getting this error in my local/development environment.

    2. Yes, I picked the code from code project.

    Can I get a solution to it?

    Thanks!

    Tuesday, June 25, 2013 12:33 PM
  • User-718146471 posted

    What version of the Word Interop DLL are you using? If its the wrong version, it will absolutely not work.

    Tuesday, June 25, 2013 12:41 PM
  • User910499198 posted

    I've tried with 2-3 versions. May i know what version is needed for it?

    Tuesday, June 25, 2013 12:58 PM
  • User-718146471 posted

    Word 2003 I think should be V11 of the interop.

    Tuesday, June 25, 2013 1:01 PM
  • User910499198 posted

    Yes, I've already tried using Version 11.0. Same error. Any other way out?

    Tuesday, June 25, 2013 1:18 PM
  • User-718146471 posted

    It almost seems like you don't have write permissions on those three folders under Files. The asp.net user account should have at least Modify permissions on Copies, OriginalDoc, and Output from Windows Explorer.  Can you check?

    Tuesday, June 25, 2013 1:42 PM
  • User910499198 posted

    I do have modify persmision on those folders. Also, I could generate PDFs and Excels on the same folder.

    Tuesday, June 25, 2013 2:28 PM
  • User910499198 posted

    Is there any way, I can merge the word documents?

    Wednesday, June 26, 2013 6:40 AM
  • User-718146471 posted

    Ok, what permissions does your asp.net user account have over the windows TEMP folder? Does your asp.net user have full control in the BIN  & content folders where those files live?

    Wednesday, June 26, 2013 11:39 AM
  • User-718146471 posted

    Ok, what I see here is it needs to have its project upgraded by hand. Give me a few minutes and I'll send you a PM once I get it working on dot net 4.

    Wednesday, June 26, 2013 11:46 AM
  • User-718146471 posted

    Apparently, the code base the article provided is far too archaic to be converted to a modern framework beyond asp.net 1.1. So I'm going to come up with a different solution for you.

    Wednesday, June 26, 2013 12:18 PM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 26, 2013 1:14 PM