We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How can i Insert image to defined position?

hi Miklovan,
I want to insert an image to my documents. but i dont know image position in document. Users could be put image tag to everywhere of the document.
Simply users write in document tag. and then i will find tag then i will remove it and insert an image instead of tag.
how can i do this?
thanks for care
Ahmet Demirel

The easiest way to do this is using document range replacement with replace evaluator.
Here is a sample code:

private void IncludeImage()

    Document doc = Open("Doc1.doc");
    doc.Range.Replace(new Regex(@"\"), new ReplaceEvaluator(IncludeImageEvaluator), false);
    SaveShow(doc, "Doc1 Out.doc");
private ReplaceAction IncludeImageEvaluator(object sender, ReplaceEvaluatorArgs e)

    DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document);
    // Eraze "" text.
    e.Replacement = "";
    // commit replacement
    return ReplaceAction.Replace;

Best regards,

thanks but when I compile with Aspose Words, an error has been come out.
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document); //Error line


Thanks for your inquiry. Use the following code:

// Create DocumentBuilder
DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

Best regards.

Can someone translate this to VB? There is no “ReplaceEvaluator” available.


Thanks for your request. There were a few breaking changes to the API in version 9.2/9.3 You can find full details of these changes in the migration article:
ReplaceEvaluator delegate replaced with the IReplacingCallback Interface.
Please see the following link to find an example:
Best regards,