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

Free Support Forum - aspose.com

InsertHtml() <a></a> links not working as expected when url entered as text

We have discovered an issue when we are trying to link to websites when we are generating word files and providing content via the “InsertHTML()”

In the html code we have a link as so:<a href="http://www.example.com">www.example.com</a> as one would expect I would expect the output to display just ‘www.example.com’ and when clicked upon it opens the link. Which it does but it is including the server path reference as a prefix. ie C:\inetpub\www\www.example.com

Now if I update the html code to include the ‘http\https’ in my text <a href="http://www.example.com">http://www.example.com</a> it is now working as expected and opens the link to example.com

One would expect that the first example would work just like if I provided the link as so <a href="http://www.example.com">Click Here</a> and display the text between my <a> tags and have the link being defined by the href value. But this doesn’t appear to be the case when a partial url is defined between the tags whether it be example.com or www.example.com

@cjstolte I cannot to reproduce the problem using the latest 22.1 version of Aspose.Words for .NET. I used the following code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml("<a href=\"http://www.example.com\">www.example.com</a>");

// Open the document and check how hyperlink is inserted.
doc = new Document(@"C:\Temp\out.docx");
FieldHyperlink hyperlink = (FieldHyperlink)doc.Range.Fields[0];
Assert.AreEqual("http://www.example.com", hyperlink.Address);
Assert.AreEqual("www.example.com", hyperlink.DisplayResult);

Which version of Aspose.Words do you use? Could you please attach your output document here for our reference?

@alexey.noskov Potentially afraid of that but I supposed hopefully good news. I tried a quick glance/search on change logs. We are currently on version 20.7

With the document being for a client I don’t feel comfortable posting here but would be happy to PM if you would like.

@cjstolte I have checked the code using the old 20.7 version and still the hyperlink is inserted properly on my side. Here is the output produced by the code from my previous post: out.docx (7.2 KB)
Could you please provide a simple code example, which will allow me to reproduce the problem on my side? I will check with your code and provide you more information.

Thanks for verifying that. After taking a further look what I thought was the HTML being passed in might not be what I fully thought. Looks like we be doing some regex replacements on it somewhere else and looks to be impacting the links.

I have yet to fully verify this but my suspicion is this is where my problems are sourcing from. I appreciate the help you have provided @alexey.noskov

@cjstolte Please feel free to ask in case of any issues. We are always glad to help you.