Inserting image with InsertHtml()

While inserting images with DocumentBuilder.InsertHtml(), nothing happens. (I am using aspose.words 4.2.4.0 ) My html string is bellow:

<img class="" height="171" alt="" width="397" src="/images/image.gif" /

Could you help please.

Hi
Thanks for your request. Try to use full path to image. See the following example.

builder.InsertHtml("<img alt='' src='E:/Projects/Aspos.words/Tests/TestTwo/bin/073_89434_ladybug/test.jpg' />");

Or use DocumentBuilder.InsertImage method.
I hope that it will help you.

Thanks a lot.

Sorry, I tried this; but did not work.

docBuilder.InsertHtml("<img alt='' src='c:/inetpub/wwwroot/images/image.gif'/>");

Hi
This code works fine for me. Please make sure that the image exists on the specified path. Please attach the image and some code that you use to generate document.
Best regards.

I am sure that the image exists in the specified path.

Hi
I try to use your code, and it works fine in me side. For testing I use the following code. I have done some modification in your regular expression.

public void TestInsertImageHTML_uc()
{
    Document doc = new Document(@"073_89434_ladybug\in.doc");
    for (int i = 0; i <= 1; i++)
        doc.Range.Replace(new System.Text.RegularExpressions.Regex(i.ToString()), new ReplaceEvaluator(IncludeImageEvaluator), false);
    doc.Save(@"073_89434_ladybug\out.doc");
}
ReplaceAction IncludeImageEvaluator(object sender, ReplaceEvaluatorArgs e)
{
    DocumentBuilder docBuilder = new DocumentBuilder(e.MatchNode.Document);
    docBuilder.MoveTo(e.MatchNode);
    if (e.MatchNode != null)
    {
        string icerik = "";
        // this code works; but nothing happens
        docBuilder.InsertHtml(icerik);
    }
    else
        e.Replacement = "";
    return ReplaceAction.Replace;
}

Best regards.

Hi;
Even I changed my regEx as yours, nothing changed. I don’t understand what is wrong.
Is it possible you to send me a small demo?
Thanks

Hi
Try to use the following html string.

string icerik = "<img alt='' src='file:///E:/Projects/Aspos.words/Tests/TestTwo/bin/073_89434_ladybug/test.jpg' />";

Also see the attachment. There is the demo console application.
Best regards.

Hi Vitaly;
Thanks for the demo application. It doesn’t work on my computer. But I tested it on a friend’s computer and it worked. It doesn’t write anything to out.doc on my computer.
What might be the problem? Have you any idea?
Thanks a lot.

Hi
Does demo application create out.doc? Or is created out .doc empty?
Best regards.

Hi Vitaly;
out.doc is created empty on my cumputer; but it works on friend’s. And also, I wrote a web application and it didn’t work even on friend’s computer. I think there is a problem related with web applications. I’ve attached the application I wrote.
Thanks a lot.

Hi
I see that you use Visual Studio 2003 .NET framework 1.1. I have created demo application in VS 2005 .NET framework 2.0. I have created new demo in VS 2003. See attachment.
Also note if you start an ASP.NET web application ASPNET account will be used by the ASP.NET worker process (aspnet_wp.exe). For security reason this user has only some privileges. That’s why you should place your image in the same folder with your application.
Best regards.

Hi;
I placed the image in the same folder with my application and nothing happend again. Could you change my web application created in vs 2003 please?
Thanks.

Hi
Please add to your application new folder with name “Images”. Add to this folder your image. Then use the following code.

protected void Button1_Click(object sender, System.EventArgs e)
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    string html = "<img alt='' src='file:///"+Request.MapPath("Images/test.gif") + "' />";;
    builder.InsertHtml(html);
    doc.Save(@"C:\Temp\out.doc");
}

I hope that it will help you.

I’m sorry; but it is not still working.

Here, try to put test.gif to your application folder and try with this code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Image should reside in the folder that is accessible by ASPNET account.
// In this case it is located in the application folder.
// For example, C:\Inetpub\wwwroot\WebApplication1\test.gif.
html = "<img alt='' src='" + Server.MapPath("test.gif")+"' />";
builder.InsertHtml(html);
doc.Save("Test.doc", SaveFormat.Doc, SaveType.OpenInWord, Response);

It doesn’t work.

Well, it works on my side. Please check the attached project.

Thanks a lot for the application.
But; the created document is empty. What might be the reason it not to work on my side?
(I tried it on a friend’s computer; but nothing happend)