1-888-365-2779
+1-888-365-2779
Try Now
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
    Registered:
    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  
                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
  2. Nikifor
    Nikifor avatar
    232 posts
    Registered:
    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.


    Greetings,
    Nikifor
    the Telerik team

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