Bookmark.InsertFile Method (String, Object, Object, Object, Object)

 

Inserts all or part of the specified file into the Bookmark control.

Namespace:   Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

void InsertFile(
	string FileName,
	ref object Range,
	ref object ConfirmConversions,
	ref object Link,
	ref object Attachment
)

Parameters

FileName
Type: System.String

The path and file name of the file to be inserted. If you do not specify a path, Microsoft Office Word assumes the file is in the current folder.

Range
Type: System.Object

If the specified file is a Word document, this parameter refers to a bookmark. If the file is another type (for example, a Microsoft Office Excel worksheet), this parameter refers to a named range or a cell range (for example, R1C1:R3C4).

ConfirmConversions
Type: System.Object

true to have Word prompt you to confirm conversion when inserting files in formats other than the Word Document format.

Link
Type: System.Object

true to insert the file by using a F:Microsoft.Office.Interop.Word.WdFieldType.wdFieldIncludeText field.

Attachment
Type: System.Object

true to insert the file as an attachment to an e-mail message.

Calling this method might delete the Bookmark control.

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example adds a Bookmark control to the document and then inserts a file into the bookmark. This example requires that you have a document named Sales.docx at the root of the C directory.

This example is for a document-level customization.

private void BookmarkInsertFile()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");

    string FileName = "C:\\Sales.docx";
    object ConfirmConversions = false;
    object Link = false;
    object Attachment = false;

    bookmark1.InsertFile(FileName, ref missing, ref ConfirmConversions,
        ref Link, ref Attachment);
}
Return to top
Show: