+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Export to excel for news letter subscribers

Export to excel for news letter subscribers

26 posts, 0 answered
  1. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    08 Jun 2010
    Link to this post
    In sitefinity all the news letter subscribers are displaying using GridView.I want to export all the subscribers to excel as the rad editor is providing export to excel option.Can you please suggest the process.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Jun 2010
    Link to this post
    Hi kiran,

    Here is a sample code that exports FirstName, LastName and Email of a subscriber to CSV list that you can open with Excel

    public void WriteToCSV()
        {
            DataManager manager = new DataManager();
            IList<ISubscriber> sub = new List<ISubscriber>();
            IList subscribers = manager.GetSubscribers();
            foreach (ISubscriber s in subscribers)
            {
                sub.Add(s);
            }
             
            string attachment = "attachment; filename=SubscribersList.csv";
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", attachment);
            HttpContext.Current.Response.ContentType = "text/csv";
            HttpContext.Current.Response.AddHeader("Pragma", "public");
     
            WriteColumns();
     
            foreach (ISubscriber letterSubsciber in sub)
            {
                WriteUserInfo(letterSubsciber);
            }
            HttpContext.Current.Response.End();
        }
     
        private static void WriteColumns()
        {
            string columnNames = "FirstName, LastName, Email";
            HttpContext.Current.Response.Write(columnNames);
            HttpContext.Current.Response.Write(Environment.NewLine);
        }
     
        private static void WriteUserInfo(ISubscriber lettersubscriber)
        {
            StringBuilder stringBuilder = new StringBuilder();
            AddComma(lettersubscriber.FirstName, stringBuilder);
            AddComma(lettersubscriber.LastName, stringBuilder);
            AddComma(lettersubscriber.Email, stringBuilder);
            HttpContext.Current.Response.Write(stringBuilder.ToString());
            HttpContext.Current.Response.Write(Environment.NewLine);
        }
     
        private static void AddComma(string value, StringBuilder stringBuilder)
        {
            stringBuilder.Append(value.Replace(',', ' '));
            stringBuilder.Append(", ");
        }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    09 Jun 2010
    Link to this post
    Hi,Thanks for your reply.
    i have created two subscription groups.Each group has "Newsletters to this group" and  "subscribers" link.when click on subscribers link all the subscribers under that group are displaying using grid view.I want to keep a button on top of the grid.When click on that button all the subscribers under this group need to export to excel.How to edit the template to keep the button over the grid and how to implement its functionality.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    09 Jun 2010
    Link to this post
    Hi kiran,

    You have to modify Sitefinity\Admin\ControlTemplates\Notifications\SubscribersTemplate.ascx. You can subscribe for RowDataBound event of the RadGrid control and create a list of subscribers.

    public void Page_Load(object sender, EventArgs e)
    {
        this.GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
    }
     
     
     
    void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Telerik.Notifications.Data.GroupSubscriber subscriber = e.Row.DataItem as Telerik.Notifications.Data.GroupSubscriber;
        }
    }

    Then use a button to export this list

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    09 Jun 2010
    Link to this post
    Hi thanks for your reply.
    I have tried to add c# code in subscriberstemplate.ascx by adding script tag.But it was not allowing to add script tag.Can you suggest me the possible solution.

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    09 Jun 2010
    Link to this post
    Hello kiran,

    Create a code behind of the template - add Control, Language directive. Another option would be writing the code inline.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    10 Jun 2010
    Link to this post
    iam not able to add code behind file.its throwing errors.I was stuck with this.Can you send me the whole template.
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Jun 2010
    Link to this post
    Hello kiran,

    The CodeBehind should be compiled into a dll before being used. Try using CodeFile instead (compiled at runtime). More information can be found here: So What is it Code Behind or Code File??

    All the best,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    10 Jun 2010
    Link to this post
    Hi,
    I have tried to add c# code in code file by adding script tag.But it is still not allowing to add me.Can you please send me the template by adding the code.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Jun 2010
    Link to this post
    Hi kiran,

    Here is the code

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %>
    <%@ Register TagPrefix="sfMsg" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms.Web.UI" %>
     
    <script type="text/javascript">
                    // Called when a window is being closed.
                    function OnClientclose(radWindow)
                    {                   
                        __doPostBack('__Page', 'MyCustomArgument');
                    }                           
    </script>
     
    <script type="text/C#" runat="server">
         
     
        public void Page_Load(object sender, EventArgs e)
        {
             
            exportSubscribers.Click += new EventHandler(exportSubscribers_Click);
        }
     
        void exportSubscribers_Click(object sender, EventArgs e)
        {
           
           // here implement the logic that will write to the csv
        }
     
     
    </script>
     
    SubscribersTemplate
     
    <div class="ToolsAll">
        <sfMsg:messagecontrol runat="server" id="message">
            <itemtemplate>
                <asp:Label runat="server" ID="messageText"></asp:Label>
            </itemtemplate>
        </sfMsg:messagecontrol>
        <asp:Button runat="server" ID="exportSubscribers"  Text="ExportSubscribers" />
        <asp:LinkButton ID="addSubscriberbtn" runat="server" CssClass="CmsButLeft new" CausesValidation="false" permission="Manage">
            <strong class="CmsButRight light">
                <asp:Literal ID="Literal12" runat="server" Text="<%$Resources:AddSubscriber %>"></asp:Literal></strong></asp:LinkButton>
        <asp:PlaceHolder ID="searchWindow" runat="server" Visible="false">
            <div class="searchItems">
                <div class="searchInputs">
                    <asp:Label ID="Label3" AssociatedControlID="searchField" Text="<%$Resources:SearchSubscribersBy %>"
                        runat="server"></asp:Label>
                    <asp:DropDownList ID="searchField" runat="server">
                    </asp:DropDownList>
                    <asp:Label ID="Label2" AssociatedControlID="searchWords" Text="<%$Resources:For %>"
                        runat="server"></asp:Label>
                    <asp:TextBox ID="searchWords" CssClass="searchString" runat="server"></asp:TextBox>
                    <asp:Button ID="searchButton" Text="<%$Resources:Search %>" runat="server" CssClass="searchButton" />
                </div>
            </div>
        </asp:PlaceHolder>
        <div class="clear">
            <!-- -->
        </div>
        <div runat="server" id="newSubscriberhld" style="display: none" permission="Manage">
            <div class="simple expandnew">
                <div class="set">
                    <fieldset class="setIn">
                        <h3>
                            <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:AddSubscriber %>"></asp:Literal></h3>
                        <ol>
                            <li>
                                <asp:Label ID="emaillbl" AssociatedControlID="emailtxt" runat="server"><strong>
                                    <asp:Literal ID="Literal6" runat="server" Text="<%$Resources:Email %>"></asp:Literal>
                                    *</strong> <em id="emailLabel" runat="server"></em></asp:Label>
                                <asp:TextBox ID="emailtxt" Text="" runat="server" MaxLength="100" ValidationGroup="CreateNew"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="emailvalidator" runat="server" ControlToValidate="emailtxt"
                                    ValidationGroup="CreateNew" Display="Dynamic" EnableViewState="False" CssClass="validMessage"
                                    SetFocusOnError="True" Enabled="false">
                                    <strong>
                                        <asp:Literal ID="Literal10" runat="server" Text="<%$Resources:ReceiveNewslettersExample %>"></asp:Literal>
                                    </strong>
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="regularExpressionValidator1" runat="server" ControlToValidate="emailtxt"
                                    ValidationGroup="CreateNew" Display="Dynamic" EnableViewState="false" CssClass="validMessage"
                                    SetFocusOnError="true" ValidationExpression="\s*\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*"
                                    Enabled="false">
                                    <strong>
                                        <asp:Literal ID="literal22" runat="server" Text="<%$Resources:InvalidEmail %>"></asp:Literal>
                                    </strong>
                                </asp:RegularExpressionValidator>
                            </li>
                            <li>
                                <asp:Label ID="fnamelbl" AssociatedControlID="fnametxt" runat="server">
                                    <asp:Literal ID="Literal14" runat="server" Text="<%$Resources:FirstName %>"></asp:Literal>
                                    <em id="Em1" runat="server"></em></asp:Label>
                                <asp:TextBox ID="fnametxt" MaxLength="50" Text="" runat="server"></asp:TextBox>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
                                    ControlToValidate="fnametxt" ValidationGroup="CreateNew" ValidationExpression="[\S]*"
                                    ErrorMessage="" Display="Dynamic" EnableViewState="false" CssClass="validMessage" >
                                <strong>
                                    <asp:Literal ID="literal5" runat="server" Text="Name must contain only word characters."></asp:Literal>
                                </strong>
                            </asp:RegularExpressionValidator>
                            </li>
                            <li>
                                <asp:Label ID="lnamelbl" AssociatedControlID="lnametxt" runat="server">
                                    <asp:Literal ID="Literal11" runat="server" Text="<%$Resources:LastName %>"></asp:Literal>
                                    <em id="Em2" runat="server"></em></asp:Label>
                                <asp:TextBox ID="lnametxt" MaxLength="50" Text="" runat="server"></asp:TextBox>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
                                    ControlToValidate="lnametxt" ValidationGroup="CreateNew" ValidationExpression="[\S]*"
                                    ErrorMessage="" Display="Dynamic" EnableViewState="false" CssClass="validMessage" >
                                <strong>
                                    <asp:Literal ID="literal33" runat="server" Text="Name must contain only word characters."></asp:Literal>
                                </strong>
                            </asp:RegularExpressionValidator>
                            </li>
                        </ol>
                        <p class="button_area clearfix">
                            <asp:LinkButton ID="addbtn" runat="server" CssClass="CmsButLeft okdark" ValidationGroup="CreateNew">
                                <strong class="CmsButRight dark">
                                    <asp:Literal ID="Literal13" runat="server" Text="<%$Resources:Add %>"></asp:Literal>
                                </strong>
                            </asp:LinkButton>
                        </p>
                        <p>
                            <asp:Literal ID="Literal18" runat="server" Text="<%$Resources:YouCanAlso %>"></asp:Literal>
                            <asp:LinkButton ID="addCmsUserbtn" Text="<%$Resources:AddRegisteredCMSUsers %>" runat="server"
                                CausesValidation="false"></asp:LinkButton>
                        </p>
                        <p class="closeNewItemBox">
                            <asp:LinkButton ID="closebtn" runat="server" CssClass="cmscclcmd" CausesValidation="false"
                                Text="<%$Resources:Close %>"></asp:LinkButton>
                        </p>
                    </fieldset>
                </div>
                <div class="bottom">
                    <div>
                        <!-- -->
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="workArea insert">
        <div class="mainForm alternativeGrid">
            <div class="listHeader">
                <h1>
                    <asp:Literal ID="grpNameltl" runat="server"></asp:Literal></h1>
                (
                <asp:LinkButton ID="deletebtn" runat="server" Text="<%$Resources:Delete %>" CausesValidation="false" permission="Manage" />
                <asp:Label ID="thisGroupltrl" runat="server" Text="<%$Resources:ThisGroup %>" permission="Manage"></asp:Label>
                <span id="seperatedSection" runat="server" permission="Manage">
                    <asp:Literal ID="Seperatorltrl" runat="server" Text="<%$Resources:Separator %>"></asp:Literal></span>
                <asp:LinkButton ID="viewNewslettersbtn" runat="server" CausesValidation="false" Text="<%$Resources:ViewNewslettersToThisGroup %>" />
                )
     
     
     
            </div>
            <telerik:RadWindowManager ID="radWindowManager" runat="server">
                <windows>
                    <telerik:RadWindow ID="DialogWindow" Behaviors="Close"
                        Modal="true" runat="server" NavigateUrl="~/Sitefinity/Admin/ManageRecepients.aspx"
                        OnClientClose="OnClientclose" Width="632" Height="470" Skin="Sitefinity" EnableEmbeddedSkins="false">
                    </telerik:RadWindow>
                </windows>
            </telerik:RadWindowManager>
            <div class="subscribersGroupActions">
                <h2>
                    <asp:Literal runat="server" ID="gridTitleltl"></asp:Literal></h2>
                <span runat="server" id="cmsUserHld" visible="false" style="display: inline;">
                    <asp:Label ID="label1" runat="server" Text="<%$Resources:AmongThem %>"></asp:Label>
                    <asp:LinkButton ID="cmsUsersCountbtn" runat="server"></asp:LinkButton>
                    <asp:Label ID="rolesCountlbl" runat="server"></asp:Label>
                    <asp:Repeater ID="cmsRepeater" runat="server">
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="roleNamebtn" Text='<%#DataBinder.Eval(Container, "DataItem")%>'
                                CommandArgument='<%#DataBinder.Eval(Container, "DataItem")%>'></asp:LinkButton>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Label ID="label2" runat="server" Text="<%$Resources:RightBracket %>"></asp:Label>
                        </FooterTemplate>
                    </asp:Repeater>
                </span>
                <asp:PlaceHolder ID="selectionHldr" runat="server">
                    <p class="unsubscribeSelected" id="selectionSection" runat="server" permission="Manage">
                        <asp:Literal ID="Literal20" runat="server" Text="<%$Resources:SelectSubscribersAnd %>"></asp:Literal>
                        <asp:LinkButton runat="server" ID="unsubscribeSelectedbtn" Text="<%$Resources:Unsubscribe %>"
                            CommandName="unsubscribeSelected" />
                        <asp:Literal ID="Literal21" runat="server" Text="<%$Resources:Them %>"></asp:Literal>
                    </p>
                </asp:PlaceHolder>
            </div>
            <asp:GridView ID="GridView1" AllowPaging="true" AllowSorting="true" PageSize="20"
                AutoGenerateColumns="false" GridLines="none" CssClass="listItems" runat="server">
                <Columns>
                    <asp:TemplateField ItemStyle-CssClass="check">
                        <HeaderTemplate>
                            <asp:CheckBox ID="checkAll" runat="server" CssClass="check" />
                        </HeaderTemplate>            
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="rowCheck" CssClass="check" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$Resources:Email %>" ItemStyle-CssClass="gridContentTitle">
                        <ItemTemplate>
                            <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Subscriber.Email")%>'> </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$Resources:UserName %>">
                        <ItemTemplate>
                            <asp:Label ID="lblusername" runat="server" Text=''> </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Last name">
                        <ItemTemplate>
                            <asp:Label ID="lbllastname" runat="server" Text='<%# Eval("Subscriber.LastName")%>'> </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="First name">
                        <ItemTemplate>
                            <asp:Label ID="lblfirstname" runat="server" Text='<%# Eval("Subscriber.FirstName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="SubscribtionDate" HeaderText="<%$Resources:SubscribedOn %>" />
                    <asp:ButtonField ButtonType="Link" CommandName="Unsubscribe" HeaderText="<%$Resources:Unsubscribe2 %>"
                        Text="<%$Resources:Unsubscribe2 %>" ItemStyle-CssClass="gridActions" />
                    <asp:TemplateField HeaderText="Edit">
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="editbtn" Text="Edit"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$Resources:Registered %>">
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="profilebtn"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:PlaceHolder ID="emptyWindow" runat="server">
                <div id="empty">
                    <h2 class="gridTitle">
                        <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:NoSubscribers %>"></asp:Literal></h2>
                    <p>
                        <strong>
                            <asp:LinkButton ID="createNewEmpty" runat="server" Text="<%$Resources:SubscribeNowAtThisGroup %>"
                                CssClass="mainLink" permission="Manage"></asp:LinkButton></strong><!--<br />
                        <asp:Literal ID="Literal3" runat="server" Text="<%$Resources:Or %>"></asp:Literal>, <a href="http://www.sitefinity.com/sf3/faq.html#ab"
                            target="_blank">
                            <asp:Literal ID="Literal4" runat="server" Text="<%$Resources:CheckFAQ %>"></asp:Literal></a>--></p>
                </div>
            </asp:PlaceHolder>
        </div>
    </div>


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  11. kiran
    kiran avatar
    13 posts
    Registered:
    04 Jun 2009
    11 Jun 2010
    Link to this post
    Hi,
    Thanks for your great response.
  12. Nachitous
    Nachitous avatar
    15 posts
    Registered:
    09 Aug 2010
    11 Aug 2010
    Link to this post
    Hi, I'm the same from _this_ thread, I used what you suggest here to make a csv file, it's not quite what I was looking for, but was useful any way. Thanks.
    The only problem I have with this, is that VisualStudio can't find the method manager.GetSubscribers(); in:
    protected void btnExportEMailAddresses_Click(object sender, EventArgs e)
        {
            {
                DataManager manager = new DataManager();
                System.Collections.Generic.IList<Telerik.Newsletters.ISubscriber> sub = new System.Collections.Generic.List<Telerik.Newsletters.ISubscriber>();
                IList subscribers = manager.GetSubscribers();
                foreach (Telerik.Newsletters.ISubscriber s in subscribers)
                {
                    sub.Add(s);
                }
     
    //rest of the code as is above

    I don't know if it helps, but I'm using Sitefinity v3.6

    Thanks for the antetion, regards.
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Aug 2010
    Link to this post
    Hello Nachitous,

    The method resides in Telerik.Notifications.Newsletters.DataManager and  it is represented in 3.6 editions.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Nachitous
    Nachitous avatar
    15 posts
    Registered:
    09 Aug 2010
    11 Aug 2010
    Link to this post
    Thank you, now it's working!

    Any thoughts about merging suscriber list as I mention in the other thread? or getting a list of all suscribers no matter in wich group they are?
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    12 Aug 2010
    Link to this post
    Hi Nachitous,

    GetSubscribers method returns IList of all subscribers no matter of their group. Below is  a sample code that illustrates how to create subscriber - group relation so you can move users from one group to another.

        Telerik.Notifications.Newsletters.DataManager newsletterManager1 = new Telerik.Notifications.Newsletters.DataManager();
        Telerik.Newsletters.IGroupSubscriber gSub = null;
        Telerik.Newsletters.ISubscriber subscriber = newsletterManager1.GetSubscriber(subscriberEmail);
        //THE GUID OF OUR GROUP.
        Guid groupId = new Guid("DB851AC3-C951-4022-A508-A70FADC9EBF4");
            if (newsletterManager1.GetGroup(groupId) != null)
                if (newsletterManager1.GetGroupSubscriberRelation(groupId, subscriber.SubscriberId) == null)
                {
                    gSub = newsletterManager1.CreateGroupSubscriberRelation(
                       groupId, subscriber.SubscriberId);
                    newsletterManager1.SaveGroupSubscribers(gSub);
      
                }
    }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Kieran
    Kieran avatar
    56 posts
    Registered:
    14 Aug 2008
    20 Aug 2010
    Link to this post
    Hi

    If I want to get all the newsletters that a user is subscribed to.

    How would I go about this. (3.7 SP2)

    thanks
    Kieran
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    20 Aug 2010
    Link to this post
    Hi Kieran,

    Here is a sample code that returns all newsletters for which subscirber with email test@test.test has been subscribed

    DataManager manager = new DataManager();
     
          var letters =  manager.GetNewsletters();
          var se = "test@test.test";
     
          List<INewsletter> subscriberLetters = new List<INewsletter>();
          foreach (INewsletter letter in letters)
          {
              var groups = letter.Groups;
              foreach(GroupNewsletter g in groups)
              {
                 var subscribers =  manager.GetSubscribersOfGroup(g.GroupId, string.Empty);
                 foreach (IGroupSubscriber s in subscribers)
                 {
                     if (s.Subscriber.Email == se)
                     {
                         subscriberLetters.Add(letter);
                     }
                 }
              }
          }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Kieran
    Kieran avatar
    56 posts
    Registered:
    14 Aug 2008
    23 Aug 2010
    Link to this post
    Thanks Ivan,

    Is there anyway of just getting the Newsletter Group Name that a user has subscribed to.

    Thanks Kieran.
  19. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    23 Aug 2010
    Link to this post
    Hi Kiran,

    DataManager manager = new DataManager();
      
          var letters =  manager.GetNewsletters();
          var se = "test@test.test";
      
          List<GroupNewsletter> subscriberGroups = new List<GroupNewsletter>();
     
          foreach (INewsletter letter in letters)
          {
              var groups = letter.Groups;
              foreach(GroupNewsletter g in groups)
              {
                 var subscribers =  manager.GetSubscribersOfGroup(g.GroupId, string.Empty);
                 foreach (IGroupSubscriber s in subscribers)
                 {
                     if (s.Subscriber.Email == se)
                     {
                         subscriberGroups.Add(g);
                     }
                 }
              }
          }

    This will get you the list of groups to which a user has subscribed to.
  20. Iain
    Iain avatar
    26 posts
    Registered:
    29 Dec 2010
    31 Jan 2011
    Link to this post
    I have used the SubscriberTemplate example code from this thread along with the csv export code above ( placed within the script tag in the aspx page not the code behind and run from the button click ) and am receiving the following error:

    Compiler Error Message: CS0246: The type or namespace name 'ISubscriber' could not be found (are you missing a using directive or an assembly reference?)

  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 Jan 2011
    Link to this post
    Hi,

    Actually the sample uses

    IGroupSubscriber which is part of Telerik.Newsletters. Please add reference to Telerik.Newsletters. The ISubscriber is located under the same namespace.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  22. Iain
    Iain avatar
    26 posts
    Registered:
    29 Dec 2010
    31 Jan 2011
    Link to this post
    Whats the full syntax? Sorry I do not have a local version running of the system and am relying on FTP upload and testing via the internet, its a slow process.

    <%@ Register TagPrefix="sfLib" Namespace="..." Assembly="..." %>

    I had tried Telerik.Newsletters but this could not be located.

    ... have I got 2 threads mixed up...?
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    31 Jan 2011
    Link to this post
    Hello ,

    Here are the details

    Name: Telerik.Newsletters.IGroupSubscriber
    Assembly: Telerik.Notifications

    and

    Name: Telerik.Newsletters.ISubscriber
    Assembly: Telerik.Notifications

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  24. Charles
    Charles avatar
    36 posts
    Registered:
    18 Apr 2011
    05 Oct 2011
    Link to this post
    Hi all,

    I got the same issue when I utilize the code sample that Kiran asked for.

    And now I'm getting the same error that Iain  pointed out with the ISubscriber reference.

    The type or namespace name 'ISubscriber' could not be found (are you missing a using directive or an assembly reference?)

    So I go to add the 2 references to ISubscriber and IGroupSubscriber using these lines

    <%@ Register TagPrefix="sfMsg" Namespace="Telerik.Newsletters.IGroupSubscriber" Assembly="Telerik.Notifications" %>
    <%@ Register TagPrefix="sfMsg" Namespace="Telerik.Newsletters.ISubscriber" Assembly="Telerik.Notifications" %>

    but get this
     using namespace directive can only be applied to namespaces; 'Telerik.Newsletters.ISubscriber' is a type not a namespace

    Can someone correct my references please?
  25. Charles
    Charles avatar
    36 posts
    Registered:
    18 Apr 2011
    05 Oct 2011
    Link to this post
    I am using Sitefinity 3.7

    <%

     

    @ Register TagPrefix="sfMsg" Namespace="Telerik.Newsletters" Assembly="Telerik.Notifications" %>

    was the string I have settled with. But I am getting the following now

    This line -  IList<ISubscriber> sub = new List<ISubscriber>();
    with this error

    The non-generic type 'System.Collections.IList' cannot be used with type arguments

     

  26. Charles
    Charles avatar
    36 posts
    Registered:
    18 Apr 2011
    05 Oct 2011
    Link to this post
    Hey guys,

    I tried using the IList with the ISubscribers as the parameter but I couldn't get that to work in dev or prod.

    I settled with this. Hope this helps someone else.

    Any con's in going with my method?

    Telerik.Notifications.Newsletters.DataManager manager = new Telerik.Notifications.Newsletters.DataManager();

    var subscribers = manager.GetSubscribers();

     

    string attachment = "attachment; filename=SubscribersList.csv";

    HttpContext.Current.Response.Clear();

    HttpContext.Current.Response.ClearHeaders();

    HttpContext.Current.Response.ClearContent();

    HttpContext.Current.Response.AddHeader("content-disposition", attachment);

    HttpContext.Current.Response.ContentType = "text/csv";

    HttpContext.Current.Response.AddHeader("Pragma", "public");

     

    HttpContext.Current.Response.Write("There are " + subscribers.Count + " row(s)" + Environment.NewLine);

    foreach (ISubscriber s in subscribers)

    {

    var strFirstName = s.FirstName;

    var strLastName = s.LastName;

    var strEmail = s.Email;

    HttpContext.Current.Response.Write(strFirstName + ", " + strLastName + ", " + strEmail);

    HttpContext.Current.Response.Write(Environment.NewLine);

    }

Register for webinar
26 posts, 0 answered