Adding members CSV download to the admin Options
dannyboy wallis
Posted: Thursday, May 29, 2008 12:03:31 PM
Rank: Enthusiast

Joined: 3/13/2008
Posts: 16
Hi All

I made a little thing to download members details, and currently have it working by just plopping the aspx file in the umbraco directory, and accessing it with http://localhost/umbraco/downloadMembers.aspx (I include the code below just in case it's of any use to anyone / anyone knows of a nicer way of doing it!)

It currently works rather cheesily, as you can see, by making the user enter a hardcoded password and then spitting out the file. What I'd really like is to integrate it into the umbraco admin somewhere, so I could have a little icon, or even just a text link, in the sections bit at the bottom left, or perhaps a link in the members section to let the admins download it from there, without having to put in another password (ie. using their existing authenticated state as a logged in admin user).

I guess I have 2 questions really:

1) How to add a link to this page from within the admin somewhere
2) How to detect if they are a logged in admin user

Thanks!
Dan

Code:

<%@ Page Language="C#" %>
<%@ Import Namespace="umbraco.cms.businesslogic.member" %>

<script runat="server">
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtPassword.Text == "blahblah")
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.ContentType = "application/csv";
            Response.AppendHeader("Content-Disposition", "attachment; filename=newsletter_subscribers.csv");


            foreach (Member tempMember in Member.GetAll)
            {
                Response.Write(tempMember.Email + "\r\n");
            }
            Response.End();
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<asp:Panel id="pnlPassword" DefaultButton="btnSubmit" runat="server">
<form id="passwordForm" runat="server">
<asp:label id="Label1" runat="server" text="Please enter the password: "></asp:label>
<asp:textbox id="txtPassword" runat="server" TextMode="Password"></asp:textbox>
<asp:button id="btnSubmit" runat="server" onclick="btnSubmit_Click" text="Download" />
</form>
</asp:Panel>
</body>
</html>

tim
Posted: Thursday, May 29, 2008 12:06:57 PM

Rank: Addict

Joined: 2/19/2007
Posts: 766
Location: Belgium
Hi Danny,

Why not add your control to the dashboard of the members section. Take a look at the /config/dashboard.config file. You can add a custom usercontrol on the dashboard, just add it to the config, it should have some sample lines to get you started




Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Thursday, May 29, 2008 12:08:10 PM

Rank: Addict

Joined: 2/19/2007
Posts: 766
Location: Belgium
Something like

<section>
<areas>
<area>members</area>

</areas>

<tab caption="donwload">
<control>/usercontrols/yourusercontrol.ascx</control>
</tab>

</section>

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Thursday, May 29, 2008 12:09:37 PM

Rank: Addict

Joined: 2/19/2007
Posts: 766
Location: Belgium
btw, using the api to get the member data works fine, but won't be that fast if you have lots of members, fastes is to write a custom query that extracts the data.



Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
dannyboy wallis
Posted: Thursday, May 29, 2008 12:21:09 PM
Rank: Enthusiast

Joined: 3/13/2008
Posts: 16
Awesome, thanks... that dashboard thing looks just the ticket. I was reading about the query thing, but just did it in this shortcut way for now. I may refactor it if I get a mo.

Thanks v. much
Dan
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.