Read all Mail Merge Field in an Collection.
I was asked to read all Mail merge Files in an HTML Template and then perform a mail Merge.
The MailMerge Fields were like ##[Field]##.
So thought to use regex to find the fields.
The biggest task for me was to write a regex for Matching ##[Merge Fields]##.
This is the code that I ended with.
Private Function GetEmailMergeFields(ByVal body As String) As ListItemCollection
Dim list As ListItemCollection = New ListItemCollection
Dim pattern As String = "##[.*?]##"
Dim mymatches As System.Text.RegularExpressions.MatchCollection
Dim myregex As New System.Text.RegularExpressions.Regex(pattern)
mymatches = myregex.Matches(body)
For Each succ As System.Text.RegularExpressions.Match In mymatches
list.Add(succ.Value)
Next
Return list
End Function
Related posts:
- How to read HTML file onServer in ASP.Net
- Read a Web Page and send it as an HTML Email
- How to Use Code Behind to display text on Binding

