Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jun 06, 2018 2:51 pm

The Value of a Spire.Doc.Fields.Field is read-only. I'll like to change the Value of a Hyperlink, how do I go about it? Thanks, Simon

SimonJones65
 
Posts: 2
Joined: Thu Oct 19, 2017 1:53 pm

Thu Jun 07, 2018 3:06 am

Dear Simon,

Thanks for your inquiry.
Spire.Doc supports changing the value of hyperlink, please refer to code below.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"F:\testing\doc form\original document\Hyperlink.docx");
            foreach (Section section in doc.Sections)
            {
                foreach (DocumentObject sec in section.Body.ChildObjects)
                {
                    if (sec.DocumentObjectType == DocumentObjectType.Paragraph)
                    {
                        foreach (DocumentObject para in (sec as Paragraph).ChildObjects)
                        {
                            if (para.DocumentObjectType == DocumentObjectType.Field)
                            {
                                Field field = para as Field;
                                //find the hyperlink which you want to change
                                if (field.Type == FieldType.FieldHyperlink && field.Code == "HYPERLINK \"" + "http://www.baidu.com/" + "\"")
                                {
                                    //change the code
                                    field.Code = "HYPERLINK \"" + "http://www.e-icecblue.com" + "\"";                                   
                                }
                            }
                        }
                    }
                }
            }
            doc.SaveToFile("14085.docx",FileFormat.Docx);

After trying, if you still have the issue, please share us your input document and the code you were using for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jun 12, 2018 7:53 am

Dear Simon,

Greetings from E-iceblue.
Did you try the code I provided ? Did it solve your issue ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jun 15, 2018 8:01 am

Hi Betsy, yes, thanks, that helped - much appreciated - regards, Simon

SimonJones65
 
Posts: 2
Joined: Thu Oct 19, 2017 1:53 pm

Fri Jun 15, 2018 8:10 am

Dear Simon,

Thanks for your feedback.
Any question, just feel free to contact us.
Have a nice day.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc