More in this section

Forums / Developing with Sitefinity / More fun with Nolics - Object MailMerge

More fun with Nolics - Object MailMerge

2 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    22 Sep 2005
    18 Dec 2007
    Link to this post

    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  
                    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  
                                val = prop.GetValue(merge, prop.GetGetMethod.GetParameters).ToString()  
                            End If  
                            sContentsContent = sContent.Replace("{" + theType.Name + "." + prop.Name + "}", val)  
                    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

    <font face="verdana,helvetica" size="2">  
    Dear {UserProfile.Owner},  
    Your account has been approved to appear in the search results.   
    Please login to you account and navigate to   
     to modify your account details.  
    The Team  

    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.


  2. Nikifor
    Nikifor avatar
    232 posts
    18 May 2013
    21 Dec 2007
    Link to this post
    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.

    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
2 posts, 0 answered