Skip to main content
A newer version of this page is available. .

How to: Validate the ObjectDataSource Contained in the Spreadsheet MailMerge Template

  • 2 minutes to read

Loading the mail merge templates with the ObjectDataSource data source may cause undesired behavior if the data source is contained in a compiled assembly. This example illustrates how to use a custom service that implements the IObjectDataSourceValidationService interface to validate an ObjectDataSource contained in the loaded mail merge template and prevent the data source from loading.

Public Class MyObjectDataSourceValidationService
    Implements IObjectDataSourceValidationService

    Public Sub Validate(ByVal dataSources As IEnumerable(Of ObjectDataSource)) Implements IObjectDataSourceValidationService.Validate
        ' Do nothing to allow loading.
        ' Clear the DataSource and DataMember properties to prohibit loading.
        For Each ds As ObjectDataSource In dataSources
            If ds.Name <> "EmployeeDS" Then
                ds.DataSource = Nothing
                ds.DataMember = Nothing
            End If
        Next ds
    End Sub
End Class