0

this is my code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Word;
    namespace WindowsFormsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                object missing = System.Reflection.Missing.Value;
                object fileName = @"C:\b.docx";
                Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
                Document adoc = WordApp.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                Range rngPic = adoc.Tables[1].Cell(1, 2).Range;
                rngPic.InsertFile(@"C:\a.docx", ref missing, ref missing, ref missing, ref missing);
                WordApp.Visible = true;
            }
        }
    }

what my expectation is b.docx should contain the file a.docx rather the content of a.docx was added to the b.docx.

In clear to say i need to insert a.docx into b.docx using c# programmatically as we do insert object in word.

i need to add the whole file into the word document. not content of the file help me!!!

correction , suggestions, new codes are most welcomed.

please help me.

Anbarasan G
  • 49
  • 1
  • 9
  • I would use open xml sdk to copy the `Parts` you need from a to b. Search for office open xml sdk parts. All the images are a part, hyperlinks are a part, ... – Alexander Derck Jan 11 '16 at 10:18
  • @AlexanderDerck please give some tutorial video and examples – Anbarasan G Jan 11 '16 at 14:00
  • Have you tried recording a macro while inserting a Document as an object in order to get the basic syntax? Taking VBA to C# is no great problem, once you have that... I would expect it to be something like Selection.InlineShapes.AddOLEObject followed by the parameters with the information specific to the type of file you want to embed. – Cindy Meister Jan 11 '16 at 15:44
  • if you are using "Microsoft.Office.Interop.Word", take a look to this answer: https://stackoverflow.com/a/3322259/2753638 – Tyr Oct 28 '20 at 09:56

0 Answers0