Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Description

Excerpt

Sets the data source for the specified main document merge field to an object. The main document is the part of the document that is not within a repeat block.

Signature
C#
C#
 public void SetDataSource(System.Object value, System.String dataSourceName)
Signature
vb.net
vb.net
Public Sub SetDataSource(ByVal value As Object, ByVal dataSourceName As String)
Parameters
Param
value
value

An object to use as a data source. WordWriter will insert this value in the specified merge field.

Param
name
name

The name of the the merge field at which to insert the value.

Exceptions
Exception
ArgumentNullException
ArgumentNullException

Save will throw this exception if null (C#) or Nothing (VB.NET) is passed to the method.

Exception
ArgumentException
ArgumentException

Remarks

The data marker requires a #1 on the template. For example, to use the sample code below, you must have a merge field on the template with the data marker "FirstName.#1".

Example
Code Block
csharp
csharp
titleC#

          WordTemplate template = new WordTemplate();
          template.Open(Request.PhysicalApplicationPath + "file.doc");
          string name = txtName.Text;
          template.SetDataSource(name,"FirstName");
          template.Process();
          template.Save(Response,"file.doc",false);
          ...
        
Code Block
vb.net
vb.net
titlevb.net

          Dim template As New WordTemplate()
          template.Open(Request.PhysicalApplicationPath & "file.doc")
          Dim name As String = txtName.Text
          template.SetDataSource(name, "FirstName")
          template.Process()
          template.Save(Response, "file.doc", False)