Question

I am working with the Office 2007 PIAs and am trying to generate a large document from x number of user selected documents. Most of these documents will likely be word docs, but we want to support any file type.

Text documents work fine when inserted using InsertFile. Pictures can be inserted using InlineShapes.AddPicture. How do I embed other document types? I am looking for the functionality equivalent to drag and dropping any file into Word. If I try to use the InsertFile method, it just writes out the binary content of non text files.

Was it helpful?

Solution

To embed non-text files in Word via Interop, you use InlineShapes.AddOLEObject

I am looking for the functionality equivalent to drag and dropping any file into Word.

This does the trick for me:

public void InsertFile(Microsoft.Office.Interop.Word.Selection CurrentSelection, string FileName)
{
object FileName = fileName;
object missing = Type.Missing;
CurrentSelection.InlineShapes.AddOLEObject(ref missing, ref FileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top