Microsoft Business Intelligence Demo

By , September 29, 2009

We have a monthly users group at IE-Dynetics, and this week I will be the lucky one presenting. The topic is Microsoft Business Intelligence, and in about an hour I will demonstrate how the various Microsoft BI Products work together. If anyone is local to the Huntsville AL area and would like to attend (or just wants a free lunch), it will take place at 10am, Friday October 2nd, at 4900 Bradford Dr. in Huntsville. Lunch will be provided and served around 12.

I plan to demonstrate the following technologies and explain where each one fits into the big picture:

  • SQL Server (Including SSAS, SSIS and SSRS)
  • SharePoint Server 2007
  • SQL Server Reporting Services Integration with SharePoint
  • Excel Services and Key Performance Indicators (KPIs)
  • PerformancePoint Server 2007

Here is a link to a description of the event.

I’m looking forward to it and hope that they order in Pizza this time… I’m not a sandwich person.

Developing a SharePoint Group Email Web Part

By , September 4, 2009

There are several different situations that I have come across where there is a need to send an email to all of the members of a SharePoint group. This first came up internally when several departments wanted this feature available on their team sites. Users Just wanted to be able to click somewhere on their site and have Outlook open with an email addressed to the members of their team. We were able to find a suitable solution from Advis that did pretty much what we wanted, at least for a while. After using it for months, we found one large flaw that drove me to make my own version… It limited the total size of the string of email addresses being sent to outlook to 255 characters.

In other words, when outlook opened, the To field would be populated with the email addresses of the group of site members, but would be cut off at 255 total characters if there were a lot of members in the site. So, I decided to build my own version and solve that problem while adding a bit more functionality.
EmailWebPart

I added three options in the Editor Part.
1) Email All Site Collection Users (SPSite)
2) Email All SubSite Users (SPWeb)
3) Show All Site Security Groups

I will go over the code in some detail below and make the full code (and .wsp file) available here as I intend to do with all Web Parts I post here, but before I do I want to point out one very important thing about this Web Part. It makes use of Elevated Privileges which I went over here to pull information about the SharePoint security groups. So this allows for every user that can get to a page with this web part on it to email the members of groups that they normally may not be allowed to see. Essentially allowing them to see who is in each group. This was fine in my situation, but if you intend on using it as-is be aware of that. Alternatively, as I provide the code you could change that if you don’t like it. OK, moving on…

This Web Part only has two classes, the main web part class and a custom editor class. It is about 400 total lines of code, so I will only go over the important parts here in the blog, the rest can be downloaded here. There are three buttons that each have their own function attached to them (Mail To, CC To and BCC To) that are all very similar. I will go over the function called when Mail To is clicked below.

void mailToButton_Click(object sender, EventArgs e)
{
    try
    {
        SPSite siteColl = SPContext.Current.Site;
        SPWeb site = SPContext.Current.Web;
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite ElevatedsiteColl = new SPSite(siteColl.ID))
            {
                using (SPWeb ElevatedWeb = ElevatedsiteColl.OpenWeb(site.ID))
                {
                    SPGroupCollection groups = ElevatedWeb.Groups;
                    SPGroup group;
                    to = "";
                    if (siteUsersCheckBox.Items[0].Selected)
                    {
                        foreach (SPUser user in ElevatedWeb.SiteUsers)
                        {
                            if (user.Email != null && user.Email != "")
                                to += user.Name + " <" + user.Email + ">;";
                        }
                    }
                    if (webUsersCheckBox.Items[0].Selected)
                    {
                        foreach (SPUser user in ElevatedWeb.AllUsers)
                        {
                            if (user.Email != null && user.Email != "")
                                to += user.Name + " <" + user.Email + ">;";
                        }
                    }
                    foreach (ListItem listItem in groupCheckBox.Items)
                    {
                        if (listItem.Selected == true)
                        {
                                group = groups[listItem.Value];

                                foreach (SPUser user in group.Users)
                                {
                                    if (user.Email != null && user.Email != "")
                                        to += user.Name + " <" + user.Email + ">;";
                                }
                        }
                    }
                }
            }
        });
        if (to != "")
        {
            string response = "<script TYPE='text/javascript'>window.location='mailto:" + to + "';</script>";
            Context.Response.Write(response);
        }
        groupCheckBox.ClearSelection();
        siteUsersCheckBox.ClearSelection();
        webUsersCheckBox.ClearSelection();
    }
    catch (Exception ex)
    {
        this.Controls.Add(new LiteralControl(ex.Message));
    }
}

As you can see, the first part of the code above is checking to see what groups were selected, and building the To string accordingly. This is pretty straight forward and there are a couple of different ways you could get at the user email addresses, but this is my preferred method. The last part of the code is the very simple, yet interesting part in that it allowed me to remove the 255 character constraint of the other version. I built a little javascript with a mailto link in it, that will open up the default email client of the user (Outlook in my case) and construct a blank email with the To address filled in.

if (to != "")
{
    string response = "<script TYPE='text/javascript'>window.location='mailto:" + to + "';</script>";
    Context.Response.Write(response);
}

The only problem (if it is a problem) that I can find with my solution is if someone refreshes the page after clicking one of the web part’s buttons. In this case another email message will be opened as it is still in the postback of the page.

The editor class is straight forward, listing three choices which I outlined above. Please feel free to take a look over it and use it if you see fit. Thanks and enjoy.

Getting the SPUser object out of a person or group list field

By , September 3, 2009

So, as it turns out it is kind of tricky to get at the SPUser object stored in a person / group field.

I am building a workflow that needs to grab the email of a user, based on an SPUser object stored in a list field, and it gave me a little trouble so I decided to share. Nothing that I found online gave me the exact answer I was looking for, although this article got me headed in the right direction. Below is the code to grab the email stored in a SPUser object from a person field within a SharePoint Workflow.

SPFieldUser userField = (SPFieldUser)workflowProperties.Item.Fields.GetField("Customer");
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(workflowProperties.Item[userField.Id].ToString());
string customerEmail = fieldValue.User.Email;

Kind of ugly if you ask me, but hey it works.