# TextPartCollection Class

> An instance of the TextPartCollection class contains all text parts in a TX Text Control document. A text part can either be the document's main text, a text frame, a footnote section or a header or footer. A text frame is represented through a TextFrame object, a header or footer through a HeaderFooter object, a footnote section through a FootnoteSection object and the document's main text is represented through a MainText object. A TextPartCollection object contains all these objects in a geometric order. The first object in the collection is the main text, followed by all text frames in geometric order. At the end of the collection all headers and footers are contained also geometrically ordered. All objects in a text part collection implement the IFormattedText interface. The collection can be obtained with the TextControl.TextParts, WPF.TextControl.TextParts or ServerTextControl.TextParts property. The TextPartCollection class implements the IEnumerable and the ICollection interfaces.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 16.0
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.Core.SDK` (assembly `TXTextControl.Core.dll`, from the private NuGet feed or Text Control Offline Packages)
- **Package:** `TXTextControl.TextControl.ASP.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Implements:** `System.Collections.ICollection`, `System.Collections.IEnumerable`
- **Path:** TX Text Control .NET Server > Reference > TXTextControl > TextPartCollection Class
- **1206 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/llms-full.txt

---

### Description

An instance of the TextPartCollection class contains all text parts in a TX Text Control document. A text part can either be the document's main text, a text frame, a footnote section or a header or footer. A text frame is represented through a [TextFrame](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textframe/llms-full.txt) object, a header or footer through a [HeaderFooter](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/headerfooter/llms-full.txt) object, a footnote section through a [FootnoteSection](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/footnotesection/llms-full.txt) object and the document's main text is represented through a [MainText](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/maintext/llms-full.txt) object. A TextPartCollection object contains all these objects in a geometric order. The first object in the collection is the main text, followed by all text frames in geometric order. At the end of the collection all headers and footers are contained also geometrically ordered. All objects in a text part collection implement the [IFormattedText](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/iformattedtext/llms-full.txt) interface. The collection can be obtained with the [TextControl.TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-web/textcontrol/textparts-property/llms-full.txt), [WPF.TextControl.TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/textparts-property/llms-full.txt) or [ServerTextControl.TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/servertextcontrol/textparts-property/llms-full.txt) property. The TextPartCollection class implements the IEnumerable and the ICollection interfaces.

### Syntax

```csharp
public class TextPartCollection : ICollection, IEnumerable
```

```vbnet
Public Class TextPartCollection
    Implements ICollection, IEnumerable
```

### Examples

The following example shows how to loop through all text parts a get the first line of each part.

```csharp
foreach (object obj in textControl1.TextParts)
{
    Console.WriteLine("First Line: " + ((IFormattedText)obj).Lines[1].Text);
}
```

```vbnet
For Each obj As Object In textControl1.TextParts
    Console.WriteLine("First Line: " + DirectCast(obj, IFormattedText).Lines(1).Text)
Next
```

The following example works with text parts in the current document. The created object is then available to the surrounding document workflow.

```csharp
TextPartCollection textPartCollection = textControl.TextParts;
Console.WriteLine("Text Part Collection is ready for use.");
```

```vbnet
Dim textPartCollection As TextPartCollection = textControl.TextParts
Console.WriteLine("Text Part Collection is ready for use.")
```

---

## In This Section

- [TextPartCollection.Activate Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/activate-method/llms-full.txt): Sets the input focus to the specified text part. If the activated text part is not in the visible part of the document, the document is scrolled.
- [TextPartCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/copyto-method/llms-full.txt): Copies the elements of the collection to an array, starting at a particular index.
- [TextPartCollection.Count Property](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/count-property/llms-full.txt): Gets the number of elements contained in the collection.
- [TextPartCollection.GetEnumerator Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/getenumerator-method/llms-full.txt): Returns an enumerator that can be used to iterate through the collection.
- [TextPartCollection.GetItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/getitem-method/llms-full.txt): Gets a certain text part from the collection.
- [TextPartCollection.GetMainText Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/getmaintext-method/llms-full.txt): Gets the main text part of the document.

---

## Nearby

- **Previous:** [TextFrameInsertionMode Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textframeinsertionmode/enumeration/llms-full.txt)
- **Next:** [TextPartCollection.Activate Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol/textpartcollection/activate-method/llms-full.txt)
