foreach (Section sct in doc.Sections)
{
foreach (Paragraph para in sct.Body.GetChildNodes(NodeType.Paragraph, true))
{
foreach (Node nd in para.ChildNodes)
{
if (nd is Run)
{
Run run = (Run)nd;
if (run.Font.Name == "Symbol")
{
flag = true;
if (layout.GetStartPageIndex(run) != 0)
{
lst.Add(layout.GetStartPageIndex(run).ToString() + " : " + run.Range.Text);
pgnumlst.Add(layout.GetStartPageIndex(run));
Symbolslst.Add(run.Range.Text);
}
}
}
}
}
}
In above using para.childnodes propertity is getting error Error CS1061 ‘Paragraph’ does not contain a definition for ‘ChildNodes’ and no extension method ‘ChildNodes’ accepting a first argument of type ‘Paragraph’ could be found (are you missing a using directive or an assembly reference?)
I have updated version from 23.2.0 to 24.7.0 then error comes
I recently re-newed my licenced in sep-2024
Please help me. Alternative solution
@Nagasrinu
It seems that you are encountering an issue with the ChildNodes
property of the Paragraph
class after updating from version 23.2.0 to 24.7.0 of Aspose.Words for .NET. The error message indicates that the Paragraph
class does not have a ChildNodes
property, which suggests that there may have been changes in the API.
In the Aspose.Words API, the Paragraph
class does not expose a ChildNodes
property directly. Instead, you should use the Runs
property to access the inline-level nodes (like Run
objects) contained within a paragraph. Here’s how you can modify your code to work with the updated version:
foreach (Section sct in doc.Sections)
{
foreach (Paragraph para in sct.Body.GetChildNodes(NodeType.Paragraph, true))
{
foreach (Run run in para.Runs) // Use para.Runs instead of para.ChildNodes
{
if (run.Font.Name == "Symbol")
{
flag = true;
if (layout.GetStartPageIndex(run) != 0)
{
lst.Add(layout.GetStartPageIndex(run).ToString() + " : " + run.Range.Text);
pgnumlst.Add(layout.GetStartPageIndex(run));
Symbolslst.Add(run.Range.Text);
}
}
}
}
}
In this updated code, I replaced the loop that iterated over para.ChildNodes
with a loop that iterates over para.Runs
. This should resolve the error you are experiencing and allow you to access the text runs within each paragraph correctly.
If you continue to face issues or if there are other specific functionalities you need help with, feel free to ask!
For this scenario it’s ok but i have used it in more then 500 methods in different scenario for getting child elements of paragraph is they a way to represent same functionality(getting childnodes)
please suggest alternative code or approach
@Nagasrinu CompositeNode.GetChildNodes(NodeType.Any, false)
is an exact replacement of CompositeNode.ChildNodes
property.
In older versions CompositeNode.ChildNodes
property internally calls the above mentioned method. So each time you use CompositeNode.ChildNodes
property, CompositeNode.GetChildNodes(NodeType.Aany, false)
method is called that might have performance impact. So it was decided to remove CompositeNode.ChildNodes
property from public API.
Is There no alternative for this to get child nodes of particular node(para)
@Nagasrinu You can use Paragraph.GetChildNodes(NodeType.Any, false)
as mentioned above.