none
Problem in Merging Word Docs using Microsoft Word.Interop

    Question

  • Hello Everyone

    I am using microsoft.word.inerop DLL to merge word docs in my asp.net application.Though this works but the problem is after merging the docs it distorts the formatting of just the very first page.Margins are not in place  (right margin).Please provide me a solution to this problem.I will be very greatful.

    Here is the code I am using for merging docs

    ***************************************************************************************************************
       Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document wDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);

     wDoc.Application.Selection.Range.InsertFile(file[0], ref oMissing, ref oMissing, ref oMissing, ref oFalse);
                            
                                wDoc.Application.Selection.EndKey(ref wdStory, ref oMissing);
     object m_WordDocumentType = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
                            string combineDocName = Path.Combine(fileDirectory, "Merged Document.doc");
                            if (File.Exists(combineDocName))
                                File.Delete(combineDocName);
                            object combineDocNameObj = combineDocName;
                            wDoc.SaveAs(ref combineDocNameObj, ref m_WordDocumentType, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                            WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(wDoc);
    *****************************************************************************************************************
    Thanks a lot


    Regards
    Vivek
    • Moved by Cindy Meister MVPMVP Monday, August 03, 2009 3:48 PM not a VSTO project (From:Visual Studio Tools for Office)
    • Edited by Vivek Batra Tuesday, August 04, 2009 8:55 AM
    Monday, August 03, 2009 6:52 AM

All replies

  • VSTO is a technology that runs in-process with the Office application. Automating the interop using ASP.NET is explicitly not supported in the VSTO forum. You'll find a list of links to venues for non-VSTO, Office-related questions in the forum's Please Read First message.

    When you post a question concerning an Office application, please be sure to mention the version of Word involved. You usually should also show the code that leads to the undesired result. Without that information, it's almost impossible to give useful advice.
    Cindy Meister, VSTO/Word MVP
    Monday, August 03, 2009 9:05 AM
  • Hi Cindy

    Thanks  a lot for your suggestions.I will check out the VSTO.


    Regards
    Vivek
    Tuesday, August 04, 2009 8:56 AM