Sitefinity ASP.NET CMS - Content Management System

Support Forum Thread

Home >  Support >  Forums home > Sitefinity 3.x > Developing with Sitefinity > More fun with Nolics - Object MailMerge

Reply
bnye, 12/18/2007 5:01:18 PM

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   
<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

Reply
, 12/21/2007 7:20:27 AM
Hello bnye,

Thank you very much for bringing this to our attention. Yes, it is truly more dynamic than the string.Format() method. We will include this information in our records and will suggest it as a better solution every time we receive a similar request.

 

Thank you for your courtesy.


Greetings,
Nikifor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center