# Template Validation

DsWord is a Document Solutions product that offers a high performance library to create, load, modify, and save Word documents programmatically.

## Content

When processing a template, there may be instances of errors. It may be difficult to identify all errors at once, and it may take a long time to fix one error at a time. DsWord provides [TemplateError](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Templates.TemplateError.html) class and [Validate](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Templates.DataTemplate.Validate.html) method in [DataTemplate](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Templates.DataTemplate.html) class that enable a user to validate the templates in a document, defining which templates are malformed or wrongly used in the structure. When the user sets Validate to True, it marks erroneous templates in the document with the error information. When the user sets Validate to False, it only returns a list of errors.
Refer to the following example code to validate the template:

```csharp
// Initialize GcWordDocument.
var doc = new GcWordDocument();

// Add template data source.
doc.DataTemplate.DataSources.Add("ds", new int[] { 1, 2, 3, 4, 5 });
            
// Add template tags.
doc.Body.Paragraphs.Add("{{ds.value}}");
doc.Body.Paragraphs.Add("{{/ds}}");

// Validate the template.
var errors = doc.DataTemplate.Validate(true).ToList();

// Save the Word document.
doc.Save("Validate.docx");
```

**![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/validate-template.png)**
**Limitations**
Validate method only identifies wrong template grammar and absent datasource path errors.