Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

DocumentImageSource.FromFile(String) Method

Creates an image source object from the specified file.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v19.1.Core.dll

Declaration

[ComVisible(false)]
public static DocumentImageSource FromFile(
    string fileName
)

Parameters

Name Type Description
fileName String

A string that contains the name of the file from which to create the image.

Returns

Type Description
DocumentImageSource

A DocumentImageSource object representing the image in the document.

Remarks

The following code sample demonstrates how the FromFile method can be used to insert an image at the cursor position in the document.

Document document = server.Document;
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\\beverages.png"));

Note

When you use the FromFile method to create an image, the method locks the file until the application is closed. This happens because the method internally creates a file stream intended to load the image from the file, which is not disposed of together with the RichEditDocumentServer/RichEditControl instance and stays alive until you close the application.

If you require releasing the file while the program is running, you can use the DocumentImageSource.FromStream method to create an image and close the stream manually after the image is inserted into the document.

The following code snippets (auto-collected from DevExpress Examples) contain references to the FromFile(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also