Capitalize the first word of each bulleted or numbered item, and end each item with a period (Except for headings)

Hi Team,

Hope you doing well,

I need code to capitalize the first word of each bulleted or numbered item, and that item must ends with period.
if that was an heading we have to left them like the same.

Thanks and Regards,
Harish G

@HarishGali You can achieve this using code like the following:

Document doc = new Document(@"C:\Temp\in.docx");

// Get list of paragraphs in the document, which are list items and are not headings.
List<Paragraph> listItems = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>()
    .Where(p => p.IsListItem && !p.ParagraphFormat.IsHeading).ToList();

foreach (Paragraph p in listItems)
{
    // Capitalize the first leter of the first Run in the paragraph.
    Run firstRun = p.Runs[0];

    if (firstRun.Text.Length > 1)
        firstRun.Text = firstRun.Text[0].ToString().ToUpper() + firstRun.Text.Substring(1);
    else
        firstRun.Text = firstRun.Text.ToUpper();

    // And add period to the last run.
    Run lastRun = p.Runs[p.Runs.Count - 1];
    if (!lastRun.Text.TrimEnd().EndsWith("."))
        lastRun.Text = lastRun.Text.TrimEnd() + ".";
}

doc.Save(@"C:\Temp\out.docx");

But i need capitalize the first word not first letter, and i need the replacing should be done in paragraphs not in runs.

@HarishGali Could you please attach your input and expected output documents? We will check the issue and provide you more information.
All textual content are in Run nodes, which are children of Paragraph.

I have to capitalize the first word of paragraph, i am attaching document, please give me solution.

Harish.docx (56.1 KB)

@HarishGali You can achieve this using IReplacingCallback. The following code demonstrates the technique for your initial requirements. The attached document does not have any list items in it.

Document doc = new Document(@"C:\Temp\in.docx");

// Get list of paragraphs in the document, which are list items and are not headings.
List<Paragraph> listItems = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>()
    .Where(p => p.IsListItem && !p.ParagraphFormat.IsHeading).ToList();

FindReplaceOptions opt = new FindReplaceOptions();
opt.ReplacingCallback = new ToUpperCaseCallback();

foreach (Paragraph p in listItems)
{
    p.Range.Replace(new Regex("^([a-zA-Z]+)"), "", opt);

    // And add period to the last run.
    Run lastRun = p.Runs[p.Runs.Count - 1];
    if (!lastRun.Text.TrimEnd().EndsWith("."))
        lastRun.Text = lastRun.Text.TrimEnd() + ".";
}

doc.Save(@"C:\Temp\out.docx");
private class ToUpperCaseCallback : IReplacingCallback
{
    public ReplaceAction Replacing(ReplacingArgs args)
    {
        args.Replacement = args.Match.Value.ToUpper();
        return ReplaceAction.Replace;
    }
}

Thanks for the solution.
I also need to capitalize the first letter of the list items.

please help me with the code.

@HarishGali The code for this task has been already provide in this answer.