Programmatically Embedding another file to the word document

Hi

Many a times we want to embed some document in the word file, with the help of Insert-> File-> Select File menu item. This will copy the content of the file to the word document. This can also be done programmatically. 

String LocationOfFileToMerge = "C:\\Myfile.doc";

range.InsertFile(LocationOfFileToMerge,ref oMissing, ref oFalse, ref oFalse, ref oFalse);

We can also embed the document in the word file instead of copying the text of the document. In this case you can embed any kind of document.


Object NameForLabel = "File Name";

 

//Icon To Be Shown For Label
Object IconFileName = "C:\\IconFile.ico";

 

String LocationOfFileToMerge = "C:\\Myfile.doc";

Object ClassType = "Word.Document.8";

Object True = true;

Object False = false;

Object Missing = System.Reflection.Missing.Value;

 

range.InlineShapes.AddOLEObject(

    ref ClassType,ref LocationOfFileToMerge,ref False, ref True, ref IconFileName,

    ref Missing,ref NameForLabel, ref Missing);

Vikram

Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia