# DocumentTargetCollection.Add Method

> Inserts the specified target at the current text input position.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Method
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WinForms.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > DocumentTargetCollection.Add Method
- **616 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/add-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/add-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/add-method/llms-full.txt

---

### Description

Inserts the specified target at the current text input position.

### Syntax

```csharp
public bool Add(DocumentTarget documentTarget);
```

```vbnet
Public Function Add(documentTarget As DocumentTarget) As Boolean
```

### Parameters

| Parameter | Description |
|---|---|
| documentTarget | Specifies the document target to add. |

### Return Value

The return value is true, if the document target could be added. Otherwise it is false.

### Examples

The following example works with document targets in the current document by using `DocumentTargetCollection.Add`.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
DocumentTargetCollection documentTargetCollection = textControl.DocumentTargets;

if (!documentTargetCollection.Add(new DocumentTarget("CustomerName")))
{
    throw new InvalidOperationException("The item could not be inserted.");
}
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim documentTargetCollection As DocumentTargetCollection = textControl.DocumentTargets

If Not documentTargetCollection.Add(New DocumentTarget("CustomerName")) Then
    Throw New InvalidOperationException("The item could not be inserted.")
End If
```

---

## Nearby

- **Previous:** [DocumentTargetCollection Class](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/llms-full.txt)
- **Next:** [DocumentTargetCollection.CanAdd Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/canadd-property/llms-full.txt)
