[Test] //ExSkip
        public void ReplaceHyperlinks()
        {
            // Specify your document name here.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "ReplaceHyperlinks.doc");

            // Hyperlinks in a Word documents are fields, select all field start nodes so we can find the hyperlinks.
            NodeList fieldStarts = doc.SelectNodes("//FieldStart");

            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldHyperlink))
                {
                    // The field is a hyperlink field, use the "facade" class to help to deal with the field.
                    Hyperlink hyperlink = new Hyperlink(fieldStart);

                    // Some hyperlinks can be local (links to bookmarks inside the document), ignore these.
                    if (hyperlink.IsLocal)
                    {
                        continue;
                    }

                    // The Hyperlink class allows to set the target URL and the display name
                    // of the link easily by setting the properties.
                    hyperlink.Target = NewUrl;
                    hyperlink.Name   = NewName;
                }
            }

            doc.Save(MyDir + "ReplaceHyperlinks Out.doc");
        }
        public void ReplaceHyperlinks()
        {
            // Specify your document name here.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "ReplaceHyperlinks.doc");

            // Hyperlinks in a Word documents are fields, select all field start nodes so we can find the hyperlinks.
            NodeList fieldStarts = doc.SelectNodes("//FieldStart");
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldHyperlink))
                {
                    // The field is a hyperlink field, use the "facade" class to help to deal with the field.
                    Hyperlink hyperlink = new Hyperlink(fieldStart);

                    // Some hyperlinks can be local (links to bookmarks inside the document), ignore these.
                    if (hyperlink.IsLocal)
                        continue;

                    // The Hyperlink class allows to set the target URL and the display name
                    // of the link easily by setting the properties.
                    hyperlink.Target = NewUrl;
                    hyperlink.Name = NewName;
                }
            }

            doc.Save(ExDir + "ReplaceHyperlinks Out.doc");
        }
Esempio n. 3
0
        public void TestNodeIsInsideField()
        {
            //ExStart:
            //ExFor:CompositeNode.SelectNodes
            //ExFor:CompositeNode.GetChild
            //ExSummary:Shows how to test if a node is inside a field by using an XPath expression.
            // Let's pick a document we know has some fields in.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.MergeImage.doc");

            // Let's say we want to check if the Run below is inside a field.
            Run run = (Run)doc.GetChild(NodeType.Run, 5, true);

            // Evaluate the XPath expression. The resulting NodeList will contain all nodes found inside a field a field (between FieldStart
            // and FieldEnd exclusive). There can however be FieldStart and FieldEnd nodes in the list if there are nested fields
            // in the path. Currently does not find rare fields in which the FieldCode or FieldResult spans across multiple paragraphs.
            NodeList resultList = doc.SelectNodes("//FieldStart/following-sibling::node()[following-sibling::FieldEnd]");

            // Check if the specified run is one of the nodes that are inside the field.
            foreach (Aspose.Words.Node node in resultList)
            {
                if (node == run)
                {
                    Console.WriteLine("The node is found inside a field");
                    break;
                }
            }
            //ExEnd
        }
Esempio n. 4
0
        public void CompositeNode_SelectNodes()
        {
            //ExStart
            //ExFor:CompositeNode.SelectSingleNode
            //ExFor:CompositeNode.SelectNodes
            //ExSummary:Shows how to select certain nodes by using an XPath expression.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // This expression will extract all paragraph nodes which are descendants of any table node in the document.
            // This will return any paragraphs which are in a table.
            NodeList nodeList = doc.SelectNodes("//Table//Paragraph");

            // This expression will select any paragraphs that are direct children of any body node in the document.
            nodeList = doc.SelectNodes("//Body/Paragraph");

            // Use SelectSingleNode to select the first result of the same expression as above.
            Aspose.Words.Node node = doc.SelectSingleNode("//Body/Paragraph");
            //ExEnd
        }
Esempio n. 5
0
        public void CompositeNode_SelectNodes()
        {
            //ExStart
            //ExFor:CompositeNode.SelectSingleNode
            //ExFor:CompositeNode.SelectNodes
            //ExSummary:Shows how to select certain nodes by using an XPath expression.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // This expression will extract all paragraph nodes which are descendants of any table node in the document.
            // This will return any paragraphs which are in a table.
            NodeList nodeList = doc.SelectNodes("//Table//Paragraph");

            // This expression will select any paragraphs that are direct children of any body node in the document.
            nodeList = doc.SelectNodes("//Body/Paragraph");

            // Use SelectSingleNode to select the first result of the same expression as above.
            Aspose.Words.Node node = doc.SelectSingleNode("//Body/Paragraph");
            //ExEnd
        }
Esempio n. 6
0
        public void TestNodeIsInsideField()
        {
            //ExStart:
            //ExFor:CompositeNode.SelectNodes
            //ExFor:CompositeNode.GetChild
            //ExSummary:Shows how to test if a node is inside a field by using an XPath expression.
            // Let's pick a document we know has some fields in.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.MergeImage.doc");

            // Let's say we want to check if the Run below is inside a field.
            Run run = (Run)doc.GetChild(NodeType.Run, 5, true);

            // Evaluate the XPath expression. The resulting NodeList will contain all nodes found inside a field a field (between FieldStart
            // and FieldEnd exclusive). There can however be FieldStart and FieldEnd nodes in the list if there are nested fields
            // in the path. Currently does not find rare fields in which the FieldCode or FieldResult spans across multiple paragraphs.
            NodeList resultList = doc.SelectNodes("//FieldStart/following-sibling::node()[following-sibling::FieldEnd]");

            // Check if the specified run is one of the nodes that are inside the field.
            foreach (Aspose.Words.Node node in resultList)
            {
                if (node == run)
                {
                    Console.WriteLine("The node is found inside a field");
                    break;
                }
            }
            //ExEnd
        }