Here is a simple code snippet that allows you to send any object including a Nolics object through the function to create a MailMerge effect. Simply send it the content as string and the object to merge. We like this method better than using string.Format() as it is more dynamic.
| Public Function MergeContent(ByVal sContent As String, ByVal merge As Object) As String |
| Try |
| |
| |
| If Not merge Is Nothing Then |
| |
| Dim theType As Type = merge.GetType() |
| Dim pi As PropertyInfo() = theType.GetProperties() |
| For Each prop As PropertyInfo In pi |
| Dim s As String = prop.Name |
| ss = s |
| |
| Dim val As StringString = String.Empty |
| If prop.GetValue(merge, prop.GetGetMethod.GetParameters) Is Nothing Then |
| val = String.Empty |
| Else |
| val = prop.GetValue(merge, prop.GetGetMethod.GetParameters).ToString() |
| End If |
| |
| sContentsContent = sContent.Replace("{" + theType.Name + "." + prop.Name + "}", val) |
| |
| Next |
| |
| End If |
| |
| Return sContent |
| Catch ex As Exception |
| Return String.Empty |
| End Try |
| End Function |
And here is an example content created with a RadEditor
| <table> |
| <tbody> |
| <tr> |
| <td> |
| <font face="verdana,helvetica" size="2"> |
| Dear {UserProfile.Owner}, |
| <br/> |
| <br/> |
| Your account has been approved to appear in the YourSocialNetworkSite.com search results. |
| <br/> |
| <br/> |
| Please login to you account and navigate to |
| <a href="http://www.yoursocialnetworksite.com/accounts.aspx"> |
| http://www.yoursocialnetworksite.com/accounts.aspx |
| </a> |
| to modify your account details. |
| <br/> |
| <br/> |
| Sincerely, |
| <br/> |
| <br/> |
| The YourSocialNetworkSite.com Team |
| <br/> |
| </font> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <table> |
| <tbody></tbody> |
| </table> |
Pretty simple, notice the syntax of {UserProfile.Owner}. In this case the UserProfile object is sent to the client after approval.
Please do not hesitate to contact me if you have any questions.
Sincerely,
Ben