How to remove bullet list

Hi,
I have a question for you. I have got a document with some tags to be change to custom text. I would like to remove bullet list if it’s present, how can I do that?

This message was posted using Aspose.Live 2 Forum

Hello

Thanks for your inquiry. You can try using the following code to achieve this:

// Open document
Document doc = new Document("in.doc");
// Get all paragraphs in the document.
Node[] paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).ToArray();
// Remove paragraph if it is list item.
foreach(Paragraph paragraph in paragraphs)
{
    if (paragraph.IsListItem)
        paragraph.Remove();
}
// Save output document.
doc.Save("out.doc");

Hope this helps.
Best regards,

Hi,

Thank you very much for the reply.
Your suggestion is almost what I need, to do what I need I changed the code with paragraph.ListFormat.RemoveNumbers() instead of paragraph.Remove();

There is one more issue, the piece of code you sent to me deletes all of bullet list, I would need to remove only the bullets on the focus, not those on the whole document.

Ivan

Hello Ivan,

Thanks for your request. It is not quite clear for me what you mean “bullets on the focus”. Could you please be more specific? Also could you please attach you input and expected output documents here for testing? I will check them on my side and provide you more information.
Best regards,

Hi,

I resolved the issue with this code:

Dim paragraphs As Node() = e.MatchNode.Document.GetChildNodes(NodeType.Paragraph, True).ToArray()

'Remove the item
For Each paragraph As Aspose.Words.Paragraph In paragraphs
    If (paragraph.IsListItem) AndAlso (paragraph.GetText.Contains(mText)) Then
        paragraph.ListFormat.RemoveNumbers()
        builder.Write(Me.mTextReplace)

        Exit For
    End If
Next

but I don’t know if it is the bast way to do it.

When I said “bullet on focus” I mean that if I’m on a specific row (maybe in the half of the document, at the end, at a random point in my document) I would like to delete only the bullet at the specific row where I am and not all the bulletts in the whole document.

Hi Ivan,

Thanks for your request. It is perfect, that you already resolved the problem. Please see the following article which describes how to programmatically find a particular word or a phrase in a document using Aspose.Words:
https://docs.aspose.com/words/net/find-and-replace/
Also please try using the following code to get the paragraph which contains needed text:
Dim paragraph As Paragraph = CType(e.MatchNode.GetAncestor(NodeType.Paragraph), Paragraph)

Hope this helps.
Best regards,