More in this section

Forums / Developing with Sitefinity / GroupSubscribers

GroupSubscribers

15 posts, 0 answered
  1. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    02 Dec 2009
    Link to this post
    Hi

    I need to display a grid of the Subscribers to a group (email, firstname, lastname).  If I use the following code:
    DataManager dm = new DataManager();
    SubscribersGrid.DataSource = dm.GetGroup(idGroup).Subscribers;
            SubscribersGrid.DataBind();
    // idGroup has been retrieved previously

    If I use the above code, all I get is a list of GroupSubscribers with the GroupID and SubscriberID

    What I need is a list of ISubscriber objects, but can't find how to do this.

    Thanks for previous help.

    Andrew
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Dec 2009
    Link to this post
    Hello Andrew Wrigley,

    Here is a sample code that you can use

    DataManager dManager = new DataManager();
        IList allsubs = dManager.GetSubscribers();
        foreach (ISubscriber sub in allsubs)
        {
            string name = sub.FirstName;
            string lname = sub.LastName;
            string email = sub.Email;
        }

    You can use GridBoundColumn in your RadGrid and pass FristNAme, LastName and Email as DataFields.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    02 Dec 2009
    Link to this post
    Ivan

    The reason GetSubscribers is no good to me is that it gives me ALL the subscribers, whereas I only want the subscribers to one group...

    Or does ISubscriber have a GroupID property?

    Andrew
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    02 Dec 2009
    Link to this post
    Hi Andrew Wrigley,

    Try using IList allsubs = dManager.GetSubscribersOfGroup(GroupID, Exp);

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    Hi Ivan

    I have tried that but all I am getting back is a list of Telerik.Notifications.Data.GroupSubscriber objects, which is my problem.  For example, the following code fails on the foreach line:

        IList scribs = dm.GetSubscribersOfGroup(idGroup,"");
                string name = String.Empty;
                foreach (ISubscriber scrib in scribs)
                {
                    name = scrib.FirstName;
                }

    The error is:

    Unable to cast object of type'Telerik.Notifications.Data.GroupSubscriber' to type'Telerik.Newsletters.ISubscriber'.


    Ie, I am NOT getting back a list of ISubscriber objects.

    Andrew
  6. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    In fact, your code gives me the same error.  Ie:

    DataManager dManager = new DataManager();
        IList allsubs = dManager.GetSubscribers();
        foreach (ISubscriber sub in allsubs)
        {
            string name = sub.FirstName;
            string lname = sub.LastName;
            string email = sub.Email;
        }

    Again it fails on the foreach line.  I have loaded these users programatically, they display fine in the SiteFinity Module for Newsletters and then manage groups.

    So I have to presume that they are properly loaded, but why am I getting GroupSubscriber objects instead of ISubscriber ones?

    Andrew
  7. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    OK, what finally works is:

    foreach (Telerik.Notifications.Data.Subscriber scrib in scribs)

    But now it suddenly does what is expected... Ie, it returns a grid populated with ISubscriber objects, not GroupSubscriber objects.

    I am pretty certain I didn't change anything except the foreach line.  could it be some compilation issue that made the page use old code rather than new??

    Andrew

    anyway, all well that ends well.

    Andrew


  8. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    Now it works, now it doesn't...

    The very same line now fails (foreach (Telerik.Notifications.Data.Subscriber scrib in scribs)):

    Unable to cast object of type'Telerik.Notifications.Data.GroupSubscriber' to type'Telerik.Notifications.Data.Subscriber'.


    I have no idea what is going on.  The grid is now populated with GroupSubscriber objects, not ISubscriber objects.

    It seems completely unstable and will return what it wants.  Can this be a compilation issue?  Or what?!

    Andrew
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Dec 2009
    Link to this post
    Hello Andrew Wrigley,

    Below is the complete implementation

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Skin="Black">
    <MasterTableView>
    <Columns>
        <telerik:GridTemplateColumn HeaderText="FirstName">
            <ItemTemplate>
                <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn HeaderText="LastName">
            <ItemTemplate>
                <asp:Literal ID="Literal2" runat="server"></asp:Literal>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridTemplateColumn HeaderText="Email">
            <ItemTemplate>
                <asp:Literal ID="Literal3" runat="server"></asp:Literal>
            </ItemTemplate>
        </telerik:GridTemplateColumn>
    </Columns>
    </MasterTableView>
    </telerik:RadGrid>


    protected void Page_Load(object sender, EventArgs e)
       {
           DataManager dManager = new DataManager();
           Guid ID = new Guid("92C029AD-ACEE-48A3-9751-3CE73BA269A5");
           IList allsubs = dManager.GetSubscribersOfGroup(ID, string.Empty);
           RadGrid1.DataSource = allsubs;
           RadGrid1.ItemDataBound += new Telerik.Web.UI.GridItemEventHandler(RadGrid1_ItemDataBound);
           RadGrid1.DataBind();
       }
     
       void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
           {
               IGroupSubscriber subscrriber = (IGroupSubscriber)e.Item.DataItem;
               Literal literal1 = (Literal)e.Item.FindControl("Literal1");
               Literal literal2 = (Literal)e.Item.FindControl("Literal2");
               Literal literal3 = (Literal)e.Item.FindControl("Literal3");
               literal1.Text = subscrriber.Subscriber.FirstName;
               literal2.Text = subscrriber.Subscriber.LastName;
               literal3.Text = subscrriber.Subscriber.Email;
           }
       }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    Ivan

    Thanks, that works really well.  What worries me is that I can see no reason why my code was inferring lists of objects of different type, and of a type that was not the return type of the method I used.

    Ie, why did dm.GetSubscribersOfGroup return a list of GroupSubscriber objects and not ISubscriber objects?

    ah, well.

    Andrew


  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Dec 2009
    Link to this post
    Hello Andrew Wrigley,

    The correct type of IList objects is IGroupSubscriber.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    Thanks Ivan

    Intellisense seems to imply something else.  Is that a bug?

    Andrew
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    03 Dec 2009
    Link to this post
    Hello Andrew Wrigley,

    The reference is not correct there and have to be updated with IGroupSubscriber. Let me know if there are any other problem with the code.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  14. Andrew Wrigley
    Andrew Wrigley avatar
    63 posts
    Registered:
    01 Sep 2009
    03 Dec 2009
    Link to this post
    Ivan

    No, no other problems.  Just a spot of bother with the documentation...

    The online documentation also shows the wrong information.

    Andrew
  15. TIOS
    TIOS avatar
    48 posts
    Registered:
    22 Mar 2006
    12 Feb 2010
    Link to this post

    Thanks this article was useful as I needed to convert the subscriber group to CSV file to import into graphicmail.com.  Would be great if sitefinity 4 had export capabilities built in.

    Anyway the code I used for reference:

    Imports Telerik
    Imports Telerik.Sitefinity
    Imports Telerik.Newsletters
    Imports Telerik.Notifications.Newsletters
      
    Partial Class newslettersubscribers
        Inherits System.Web.UI.Page
      
        ''' <summary> 
        ''' Iterate over the existing groups and catch the group Id with the same group name 
        ''' </summary> 
        ''' <param name="dmManager"> newsletter data manager </param> 
        ''' <param name="strGroupName"> group name </param> 
        ''' <returns> group id </returns> 
        Private Shared Function GetGroupName(ByVal dmManager As DataManager, _
                                             ByVal strGroupName As String) As Guid
            Dim groups As IList = dmManager.GetGroups(String.Empty)
            For Each group As IGroup In groups
                If group.GroupName = strGroupName Then
                    Return group.GroupId
                End If
            Next
            Return Guid.Empty
        End Function
      
        Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
            Dim dmManager As New DataManager("Newsletters")
            Dim guid As Guid = GetGroupName(dmManager, ddlList.SelectedValue)
      
            Dim Subscribers As IList = dmManager.GetSubscribersOfGroup(guid, String.Empty)
            For Each subscriber As IGroupSubscriber In Subscribers
                Response.Write(subscriber.Subscriber.Email & "<br/>")
            Next
      
      
        End Sub
Register for webinar
15 posts, 0 answered