Sitefinity ASP.NET CMS
Support / Forums / Sitefinity 3.x: Developing with Sitefinity / More fun with Nolics - Object MailMerge

Not answered More fun with Nolics - Object MailMerge

Feed from this thread
  • bnye Master avatar

    Posted on Dec 18, 2007 (permalink)

    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

  • Telerik Admin admin's avatar

    Posted on Dec 21, 2007 (permalink)

    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

    Reply

About Telerik

Telerik, the publisher of Sitefinity CMS, is leading vendor of ASP.NET AJAX, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting and .NET ORM solutions. Building on its solid expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Created with passion, Telerik products help thousands of developers every day to be more productive and deliver reliable applications under budget and on time. Read more about Telerik

Copyright © 2002-2009 Telerik. All rights reserved. Powered by Sitefinity