Find Item in ordered list

How do I know whether I am in a ordered or unordered list, and what number each item is in an ordered list? I could not find properties which would give me this information.
I know that to detect if i’m in a list I can use Paragraph.IsListItem property
and the following properties return only Bullet
Paragraph.ListFormat.ListLevel.NumberStyle
How can I Find a number of the current list item ?
1)item1
2)item2
3)item3
Thanks

Hi
Thanks for your inquiry. Unfortunately there is no way to get list numbers using Aspose.Words. These numbers are not stored in the document. MS Word calculates list numbers on fly during opening document. However you can try to create your own method for calculating list numbers.
I created sample code for another customer to achieve similar task. Please see the following link to learn more.
https://forum.aspose.com/t/106128
Best regards.

Thanks alexey,
I tried your example & it works for some case and for others it doessn’t.
For the folowing case it’s doen’t work:

  1. Liste Hirarchie -N1
    1.1. Liste Hirarchie -N2
    1.1.1. Liste Hirarchie -N3

Matériel requis
v Note au dossier
Ø But
it reads them in the folowing order and here is the result:

ListItem(VisitRun )Liste Hirarchie -N1(VisitParagraphEnd)
ListItem(VisitRun )Liste Hirarchie -N2(VisitParagraphEnd)
ListItem(VisitRun )Liste Hirarchie -N3(VisitParagraphEnd)
(VisitParagraphStart)(VisitParagraphEnd)
(VisitParagraphStart)ListItem Bullet(VisitRun )Matériel requis(VisitParagraphEnd)
(VisitParagraphStart)ListItem Bullet(VisitRun )Note au dossier(VisitParagraphEnd)
(VisitParagraphStart)ListItem Bullet(VisitRun )But(VisitParagraphEnd)
So how can I exract the paragraph with it’s bullet???
And how can get the folowing???

  1. Liste Hirarchie -N1
    1.1. Liste Hirarchie -N2
    1.1.1. Liste Hirarchie -N3
    Best Regards

Hi
Thanks for your request. The code should work for this case. Could you please attach your document for testing? Do you need to extract text of paragraph including its bullet?
Best regards.

Yes, I want to extract the bullet with the text.
How about this one in the file:

  1. Liste Hirarchie -N1
    1.1. Liste Hirarchie -N2
    1.1.1. Liste Hirarchie -N3
    it doesn’t detect them.
    Here is the file attached.
    Thanks

Hi
Thank you for additional information. I did little modification and now ListLabelExtractor works fine with your document. Here is code I used for testing:

Document doc = new Document(@"Test012\in.doc");
// Create an object that inherits from the DocumentVisitor class.
ListItemToTxt myConverter = new ListItemToTxt();
doc.Accept(myConverter);
// Once the visiting is complete, we can retrieve the result of the operation,
// that in this example, has accumulated in the visitor.
// Save text to the file
string text = myConverter.GetText();
Console.WriteLine(text);
class ListItemToTxt : DocumentVisitor
{
    public ListItemToTxt()
    {
        mIsSkipText = false;
        mBuilder = new StringBuilder();
    }
    /// 
    /// Gets the plain text of the document that was accumulated by the visitor.
    /// 
    public string GetText()
    {
        return mBuilder.ToString();
    }
    /// 
    /// Called when a Run node is encountered in the document.
    /// 
    public override VisitorAction VisitRun(Run run)
    {
        if (run.ParentParagraph.IsListItem)
            AppendText(run.Text);
        // Let the visitor continue visiting other nodes.
        return VisitorAction.Continue;
    }
    public override VisitorAction VisitParagraphStart(Paragraph paragraph)
    {
        if (paragraph.IsListItem && paragraph.HasChildNodes)
        {
            string lable = string.Empty;
            if (paragraph.ListFormat.ListLevel.NumberStyle != NumberStyle.Bullet)
            {
                ListLabelsExtractor extractor = ListLabelsExtractor.GetLabelExtractor(paragraph.ListFormat.List);
                // Get lable of list item
                lable = extractor.GetListLabel(paragraph.ListFormat.ListLevelNumber) + "\t";
            }
            else
            {
                lable = paragraph.ListFormat.ListLevel.NumberFormat + "\t";
            }
            AppendText(lable);
        }
        return VisitorAction.Continue;
    }
    /// 
    /// Called when visiting of a Paragraph node is ended in the document.
    /// 
    public override VisitorAction VisitParagraphEnd(Paragraph paragraph)
    {
        // When outputting to plain text we output Cr+Lf characters.
        if (paragraph.IsListItem)
            AppendText(ControlChar.CrLf);
        return VisitorAction.Continue;
    }
    /// 
    /// Adds text to the current output. Honours the enabled/disabled output flag.
    /// 
    private void AppendText(string text)
    {
        if (!mIsSkipText)
            mBuilder.Append(text);
    }
    private readonly StringBuilder mBuilder;
    private bool mIsSkipText;
}

ListLabelExtractor class is attached.
Best regards,

How do I know whether I am in a bulet list or numeric list?
How do I know to witch parent list belongs a less level itemlist? example:
1 HFHFGGFG
1.1 ASDASDADAD
1.1.1 XXXXX
1.2 WQQQQQQ
1.2.1 WWWWWWW
1.2.2 FGHFGHFGH
1.3 DDDDDDD
I mean how to know that the parent of 1.3 is the 1?
I could not find properties which would give me this information.
Thanks

Hi

Thanks for your request.

  1. You can use ListLevel.NumberStyle to determine whether the list is bulleted or numbered. This property returns NumberStyle.Bullet if the list level is bulleted. See the following link for additional information:
    https://reference.aspose.com/words/net/aspose.words.lists/listlevel/numberstyle/
  2. You can determine parent list using ListLevel. The first list level has ListLevelNumber = 0 the second 1 etc.
    https://reference.aspose.com/words/net/aspose.words.lists/listformat/listlevel/
    Hope this helps.
    If you would like to get numbers of list items, there is no direct way to achieve this, list numbers are calculated on the fly by MS Word. (See ListLabelsExtractor class I have attached in my previous answer.)
    Best regards.