Free Support Forum - aspose.com

FieldHyperlink.Address property not being saved correctly


#1

Hi,

I am using Aspose 18.12.

In the attached example word file, there are 2 hyperlinks. “http://www.website2.com” and “http://wwW.webSite1.COM”. One in lowercase and one with mixed case.

When I change the first URI from “http://www.website2.com” to “http://www.website1.com”, the capitalization of the second URI changes also.

I do this by setting a new value to the FieldHyperlink.Address property.

Example Word file:
links.zip (9.4 KB)

Visual Studio C# project:
WordAspose.zip (241.1 KB)


#2

@JohnGrahamLT

Thanks for your inquiry. We have tested the scenario using the latest version of Aspose.Words for .NET 19.1 with your code example and have not found the shared issue. Could you please share your problematic and expected output documents here for our reference? We will then provide you more information about your query.


#3

Hi there,

The problem does exist in Aspose.Words for .NET 19.1.

In the example word file attached to first post there are 2 hyperlinks.

1.) http://www.website2.com/

2.) http://www.webSite1.COM/ <-- notice the capitalisation

if you use Aspose.Words to change link 1 to http://www.website.com/ (the same as link 2, but all lower case), then the character casing of link 2. changes as well.

I need to be able to change one link without the character casing of the other one changing.


#4

@JohnGrahamLT

Thanks for your inquiry. We have tested again your scenario and noticed that only the field (http://www.website2.com/) is changed in output document. Please check the attached images for detail.

We suggest you please use the following modified code snippet.

if (hyperlink.Address.Contains(@"website2.com"))
{
    Console.WriteLine("REPLACED");
    //var newVal = hyperlink.Address;
    hyperlink.Address = hyperlink.Address.Replace("website2.com", "website1.com");
    hyperlink.Result = hyperlink.Address;
}

If you still face problem, please ZIP and attach your problematic and expected output Word documents here for our reference. We will investigate how you want your final Word output be generated like and provide you more information about your query along with code.

PS : You can create your expected output document using Microsoft Word.


#5

The word document may appear like this, but the values during execution are as I have described, and as demonstrated by the VS project I attached previously.

Look at the attached image for the values during code execution:

links-aspose.JPG (15.6 KB)

This is bad; especially for character sensitive comparisons of URIs.

I need the values to be correct, in code, during execution.


#6

@JohnGrahamLT

Thanks for your inquiry. We tested the scenario using the latest version of Aspose.Words for .NET 19.1 and have not found the shared issue. Please check the attached image for detail and use Aspose.Words for .NET 19.1.


#7

Your example is printing FieldHyperlink::Result to the screen.

I am talking about FieldHyperlink::Address.

However, with some investigation, the phenomenon I am experiencing is due to how Microsoft files only store one copy of the same logical URI.


#8

@JohnGrahamLT

Thanks for your inquiry. In my previous post, the screenshot shows the output of your code. You can also test this case by using following code example.

Document doc = new Document(MyDir + "links.docx");
foreach (Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldHyperlink)
    {
        FieldHyperlink hyperlink = (FieldHyperlink)field;
        if (hyperlink.Address == null) return;

        if (hyperlink.Address.Contains(@"website2.com"))
        {
            hyperlink.Address = hyperlink.Address.Replace("website2.com", "website1.com");
            hyperlink.Result = hyperlink.Address;
            Console.WriteLine("After replacing the Address is : ");
            Console.WriteLine($"\t{hyperlink.Address}");
        }
    }
}

Console.WriteLine("Print the address");
foreach (Field field in doc.Range.Fields)
{
    if (field.Type == FieldType.FieldHyperlink)
    {
        FieldHyperlink hyperlink = (FieldHyperlink)field;
        if (hyperlink.Address == null) return;

        Console.WriteLine($"\t{hyperlink.Address}");
    }
}
doc.Save(MyDir + "19.1.docx");

Console.WriteLine("After saving the document.");
Document doc2 = new Document(MyDir + "19.1.docx");
foreach (Field field in doc2.Range.Fields)
{
    if (field.Type == FieldType.FieldHyperlink)
    {
        FieldHyperlink hyperlink = (FieldHyperlink)field;
        if (hyperlink.Address == null) return;

        Console.WriteLine($"\t{hyperlink.Address}");
    }
}

We have attached the screenshot of output. Please let us know if you have any more queries.


#9

Can you think of any reason that I am getting different results?


#10

@JohnGrahamLT

Thanks for your inquiry. Please make sure that you are using the same Word document and latest version of Aspose.Words for .NET 19.1. Moreover, please try the code example share in my previous post.


#11

we are using the same code.


#12

@JohnGrahamLT

Could you please share the screenshot of problematic output? Please also share your environment detail e.g. operating system, .NET version etc?


#13

Using your latest code snippet recommendation on the file attached to the first post:

Aspose.Words: 19.1
Visual Studio: 2017
.NET: 4.0
Configuration: x86, Debug

Windows: 10, x64
Memory: 8 GB

See attached image for results:
Capture.PNG (6.8 KB)


#14

@JohnGrahamLT

Thanks for sharing the detail. We are investigating this issue and will get back to you soon.


#15

@JohnGrahamLT

Thanks for your patience.

We have downloaded the same input document from your first post and tested the scenario at same environment. We have not found any issue with output. We have attached the screenshot of output for your kind reference.