April 2008 - Posts

Using PeopleEditor Control with Web Parts in SharePoint 2007/WSS 3.0

Ever wanted to borrow that cool AJAX like control in SharePoint 2007 (or WSS 3.0) that lets you pick and resolve users so that you can manage those users/groups and their  permissions.

The control I'm talking about is PeopleEditor (aka People Picker) and there's not much documentation out there, and the examples are not very helpful.

At some point in time last year I decided to investigate this control and find out how to get resolved items out of it, as I needed to use it and abuse it for a component of a SharePoint solution at the time.

I got some questions recently about it, so I promised that I will post a very simple example on how to use it, so here it goes:

This web part in a very crude (not recommended) way filters out the groups with permissions on a Task list on the web and allows for adding/removing users through PeopleEditor control to groups selected through the dropdown control.

(Please note that this is just to show a proof of concept, do not use this web part as is in production)

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace PplEdtr
{
    [Guid("4114de9b-ae5c-45a4-b1c0-b8e4abf4675e")]
    public class PplEdtr : System.Web.UI.WebControls.WebParts.WebPart
    {
        public PplEdtr()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        private Label dropDownListLabel;
        private DropDownList dropDownList;
        private PeopleEditor peopleEditor;

        private Button buttonAddUser;
        private Button buttonRemoveUser;
        private SPList taskList;

        private string html = null;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            string groupName = null;

            this.dropDownListLabel = new Label();
            this.dropDownList = new DropDownList();


            using (SPWeb web = SPContext.Current.Web)
            {
                taskList = web.Lists["Tasks"];
                this.dropDownList.Items.Clear();
                this.dropDownListLabel.Text = "Select the group where you want to add the desired user for the Task List: " + taskList.Title + " ";
                foreach (SPRoleAssignment role in taskList.RoleAssignments)
                {
                   
                    bool isGroup = true;
                    try
                    {
                        SPGroup group = taskList.Lists.Web.Groups[role.Member.Name];
                        groupName = group.Name;
                    }
                    catch (Exception ex)
                    {
                        isGroup = false;
                    }
                    if (isGroup == true)
                    {
                        ListItem listItem = new ListItem();
                        listItem.Text = groupName;
                        listItem.Value = groupName;
                        this.dropDownList.Items.Add(listItem);
                    }
                }
            }
            this.peopleEditor = new PeopleEditor();

            this.Controls.Add(peopleEditor);

            this.buttonRemoveUser = new Button();
            this.buttonAddUser = new Button();
            this.buttonAddUser.Text = "Add a User to the Selected Group";
            this.buttonRemoveUser.Text = "Remove a User from the Selected Group";

            this.buttonAddUser.Click += new EventHandler(buttonAddUser_Click);
            this.buttonRemoveUser.Click += new EventHandler(buttonRemoveUser_Click);
           
            this.Controls.Add(this.dropDownListLabel);
            this.Controls.Add(this.dropDownList);
            this.Controls.Add(this.buttonAddUser);
            this.Controls.Add(this.buttonRemoveUser);
        }

        private void buttonAddUser_Click(object sender, EventArgs e)
        {
            foreach (PickerEntity entity in peopleEditor.ResolvedEntities)
            {
                if (entity.IsResolved == true)
                {
                    try
                    {
                        SPGroup group = taskList.Lists.Web.Groups[dropDownList.SelectedItem.Value];

                        bool isPresent = false;
                        foreach (SPUser groupUser in group.Users)
                        {
                            if (groupUser.LoginName == entity.DisplayText)
                                isPresent = true;
                        }
                        if (isPresent == false)
                        {
                            group.AddUser(entity.DisplayText, null, null, null);
                            group.Update();
                            html = html + "<br>The selected User: " + entity.DisplayText + " has been added to the Group: " + group.Name + "</br>";
                        }
                        else
                            html = html + "<br>The selected User: " + entity.DisplayText + " already exists in the Group: " + group.Name + "</br>";
                    }
                    catch (Exception ex)
                    {
                        html = html + "<br>" + ex.Message + "</br>";
                    }
                }
                else
                    html = html + "<br>Entity " + entity.DisplayText + " is not resolved, please ensure it's resolved before you procede" + "</br>";
            }
            this.dropDownListLabel.Text = html;
        }

        private void buttonRemoveUser_Click(object sender, EventArgs e)
        {

            foreach (PickerEntity entity in peopleEditor.ResolvedEntities)
            {
                if (entity.IsResolved == true)
                {
                    try
                    {
                        SPGroup group = taskList.Lists.Web.Groups[dropDownList.SelectedItem.Value];

                        bool isPresent = false;
                        foreach (SPUser groupUser in group.Users)
                        {
                            if (groupUser.LoginName == entity.DisplayText)
                            {
                                SPUser user = group.Users[entity.DisplayText];
                                isPresent = true;
                                group.RemoveUser(user);
                                group.Update();
                                html = html + "<br>The selected User: " + entity.DisplayText + " has been deleted from the Group: " + group.Name + "</br>";
                            }
                        }
                        if (isPresent == false)
                            html = html + "<br>The User: " + entity.DisplayText + " does not exist in the selected Group: " + group.Name + "</br>";

                    }
                    catch (Exception ex)
                    {
                        html = html + "<br>" + ex.Message + "</br>";
                    }

                }
                else
                    html = html + "<br>Entity " + entity.DisplayText + " is not resolved, please ensure it's resolved before you procede" + "</br>";
            }
            this.dropDownListLabel.Text = html;
           
        }
    }
}

You can download the source code here (http://dotnet.org.za/blogs/zlatan/PplEdtr.zip)

This was done (in a huge rush) using the following:

Visual Studio 2005

SharePoint 2007/WSS 3.0 SDK 1.3

Visual Studio Extensions for SharePoint 1.1

What does it take to be a SharePoint MVP

Well here's an excellent post (http://blogs.msdn.com/sharepoint/archive/2008/04/17/sharepoint-mvps-know-how-to-have-fun-and-give-constructive-product-feedback.aspx) explaining this together with pictures of my fellow MVPs from the recent MVP Summit, which I unfortunatelly was unable to attend, but the next one I will definitely not miss. 

Posted by Zlatan | with no comments
Filed under: ,

South African Business Intelligence User Group Launch in Cape Town, a Success!! (Post Event Info)

Wow that was an awesome event, and perfect way start yet another great user group/community in Cape Town and Western Cape (we rule!!) and I'm proud that I was part of it. The event that was represented by prominent BI people from all sides of our industry also featured a brilliant presentation by John Swanepoel of Shoprite on one of the best examples I’ve seen on how BI should be done (Shoprite BI case study), I want to thank him for that and I hope to see more of his work in near future.

Also I would like to thank all the participants on the great feedback I got for my technical session on PerformancePoint Server 2007, as promised, here’s where you can download the presentation (http://www.businessintelligencesa.co.za/User%20Group/BI%20User%20Group%20PPS%20CPT.pptx)

You can get hold of the rest of the material from the session here:

http://www.businessintelligencesa.co.za/User%20Group/Forms/AllItems.aspx  

Also, here are more resources on PerformancePoint 2007 (as promised):

First of all, the very valuable TechNet Virtual Labs (I suggest you just download the manual if your cap is small):

Also MSDN “How do I.....” Articles for Planning Business Modeler (as mentioned in my session):

How do I ... in Planning Business Modeler?
How do I write a business rule?A business rule is a short program that performs a business task. Business rules are at the heart of Planning Business Modeler. You can create business rules that allocate resources, calculate forecasts, or find key performance indicators (KPIs).
How do I set up a model for shares calculation and consolidation?PerformancePoint Planning Server can perform complex consolidation operations that meet internal and external reporting requirements. You can set up a model that accurately reflects the organization structure, including subsidiary relationships and minority ownership.
How do I create an association to move data between models?In Planning Business Modeler, you can define a formal association between models so that you can precisely map data movement between source and destination, and manage the way the data is aggregated.
How do I export data with an outbound rule?You can publish semantically rich data that you developed in PerformancePoint Server to external data stores.
How do I use an assumption model?In Planning Business Modeler, you can store logical groups of baseline data in assumption models. These assumption models can be referenced by other models and they are typically used for forecasting activities. Assumption models streamline modeling activities, and help promote data integrity.

The rest of the info you can find on the PerformancePoint Server Developer Portal (http://msdn2.microsoft.com/en-us/office/bb660518.aspx)

For more info on this BI User Group or the ones in your respective area and to get more local BI and PerformancePoint info go to: (http://www.businessintelligencesa.co.za/)

Many thanks go to Shivani, and Godfrey of Microsoft for making this event a success and Business Connexion and Microsoft for sponsoring the event, thank you, you’re the best!!

                                                                                                                                                    

 

South African Business Intelligence User Group Meeting - Cape Town 15th of April 2008

If you’re not signed up for this already please do it before it’s too late, I will be giving a Technical Session on PerformancePoint Server 2007 (number 4 in the Agenda), see you there!!!

See details below:  

15 APRIL 2008

Come and share your experiences, both business and technical, at the South African Business Intelligence User Group Meeting.

Customers will be sharing case studies, partners will be showcasing evidence and techies will be giving expert advice and opinions.

Learn, Share, Grow.

Date

Tuesday 15 April 2008

Venue

Microsoft Cape Town offices
Golf Park 3
Engen House
Raapenberg Road
Mowbray

Time

13:15 to 15:30

To register: PLEASE CLICK HERE or
Call 0860 22 55 67


1. Registration
2. Welcome
3. Business Session: Shoprite BI Project
4. Technical Session: Performance Point Server
5. Discussion
6. Next Meeting
 

 

Developing Business Intelligence Solutions with SharePoint 2007 and PerformancePoint 2007

 

This session was actually scheduled for the 26th of March but we unfortunatelly had to postpone the meeting in the last minute as I needed to be in Johannesburg urgently (I'm finally back in CPT).

Here's write up from the invite (you can also download it in pdf on infromationworker.co.za under events):

S.A. Developer.net

April 2008 Meeting -
Developing Business Intelligence Solutions with SharePoint 2007 and PerformancePoint 2007

 

Please join us for an exciting session presented by Zlatan Dzinic

Overview: 

In SharePoint 2007 you can create interactive business intelligence (BI) dashboards that assemble and display business information from disparate sources by using built in Web Parts.

Microsoft Office PerformancePoint Server is an integrated performance management application. It allows users to create reports and scorecards that show performance at a glance and rules that help better understand planned and actual variances. Analysts can quickly analyze root-causes and recast plans when necessary. Customers can enter the performance management process at any point, benefiting from a common data model shared across monitoring, analytical, and planning activities.

In this talk, Zlatan brings these two powerful products together, showing how SharePoint can be used as a hosting environment for the powerful features of the new PerformancePoint product.

Speaker Bio - Zlatan Dzinic:
Zlatan's primary role is System Architect/Technical Lead (occasional PRINCE 2 Project Manager) and he also comes from an extensive C#.NET (and SQL) Development and Enterprise Content Management (ECM) background - MS SharePoint 03/07, Opentext - Livelink, Meridio, K2.NET (and other). His main focus is Developing and Architecting Office Business Applications, SharePoint 2007 Enterprise Content Management, including development of Windows Workflow Foundation (WWF), Windows Communication Foundation (WCF). He's an active Office Business Applications and SharePoint Evangelist.

 

Date: 30th April, 2008
Time: 18:30
Venue: Microsoft Cape Town (Please note the address below)
                Golf Park 3, Engen House, Raapenberg Road, Mowbray

Please RSVP (!) to Angela at Angelag@absamail.co.za  or RSVP on this thread

http://sadeveloper.net/forums/10509/ShowThread.aspx

Sponsors:

Microsoft and Business Connexion

Pimpin' Ain't Easy, But It's Necessary :)

 

This is just to let the rest of you guys that don't know yet in the community, I am your new SharePoint MVP!!! I'm still celebrating :)

I would like to thank our South African Community in general, then SADeveloper, South African MVPs, Information Worker Community and last but not least, Microsoft for your support in all my speaking events and initiatives... All of you guys are the greatest !!!!!!!!!!!!!!!!!!

I'm looking forward to working and contributing even more then before. I will write about my next two speaking events soon, so watch my blog. My site zlatandzinic.com will stay down for the time being, I'm migrating to a new url, new service provider and new platform - MOSS 2007, I will let you know as soon as it happens, so if you want to post any question (for those of you that used to on zlatandzinic.com) please do so on informationworker.co.za.

Posted by Zlatan | 7 comment(s)