officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertoleobjectasicon-x28-documentposition-string-documentimagesource-x29.md
Using file paths sourced from untrusted input may expose unauthorized files or allow unintended file access. Always validate and normalize all external paths to prevent path manipulation.
Inserts an OLE object that contains a link to the specified file. The object is displayed in the document as an icon.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
Shape InsertOleObjectAsIcon(
DocumentPosition pos,
string fileName,
DocumentImageSource icon
)
Function InsertOleObjectAsIcon(
pos As DocumentPosition,
fileName As String,
icon As DocumentImageSource
) As Shape
| Name | Type | Description |
|---|---|---|
| pos | DocumentPosition |
The position of the object’s anchor.
| | fileName | String |
A path to the file associated with the OLE object.
| | icon | DocumentImageSource |
An object used to load the icon for the OLE object.
|
| Type | Description |
|---|---|
| Shape |
The OLE object added to the document.
|
The following example inserts a linked OLE object as an icon:
Document document = wordProcessor.Document;
// Insert an OLE object. Link it to an Excel worksheet.
// The OLE object is displayed in the document as an icon.
Shape oleObject = document.Shapes.InsertOleObjectAsIcon(document.CreatePosition(1780), @"D:\ExcelWorkbook.xlsx",
DocumentImageSource.FromFile(@"Images\Excel.ico"));
// Specify the object position on the page.
oleObject.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column;
oleObject.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph;
oleObject.Offset = new PointF(0, 0);
// Specify how text wraps around the object.
oleObject.TextWrapping = TextWrappingType.TopAndBottom;
Dim document As Document = wordProcessor.Document
' Insert an OLE object. Link it to an Excel worksheet.
' The OLE object is displayed in the document as an icon.
Dim oleObject As Shape = document.Shapes.InsertOleObjectAsIcon(document.CreatePosition(1780), "D:\ExcelWorkbook.xlsx", _
DocumentImageSource.FromFile("Images\Excel.ico"))
' Specify the object position on the page.
oleObject.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column
oleObject.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph
oleObject.Offset = New PointF(0, 0)
' Specify how text wraps around the object.
oleObject.TextWrapping = TextWrappingType.TopAndBottom
Open the document in Microsoft® Word® and double-click the icon to open the file associated with the OLE object.
See Also