Thinking out Aloud

Dave Hunter's SharePoint Blog

Archive for the ‘SharePoint 2007’ Category

Programmatically create SharePoint security groups using configuration

leave a comment »

Corey Roth has a great article “A simple way to programmatically create SharePoint security groups“.  On a recent project I needed to configure security during feature activation for security restricted WebParts (the WebParts checked the current user was a member of a particular security group) but didn’t want to hardcode the values.  The article used a XML configuration to define which groups needed creating and the membership.

SharePoint supports setting the owner of a SharePoint group to be an individual user or another security group, I extended the code to support this and to set the flags which control members editing membership, request to join or leave and auto accept request to join or leave.  Here’s the updated version of CreateGroups.
private void CreateGroups(SPWeb currentSite, string groupsConfigBody)
{
            // get the xml document from the feature folder
XDocument groupsXml = XDocument.Parse(groupsConfigBody);
            // create a new anoynmous type with the group data
var groups = from sharePointGroup in groupsXml.Root.Elements(“Group”)
select new
{
                             Name = sharePointGroup.Attribute(“Name”).Value,
Owner = sharePointGroup.Attributes(“Owner”).Any() ? sharePointGroup.Attribute(“Owner”).Value : null,
Description = sharePointGroup.Attributes(“Description”).Any() ? sharePointGroup.Attribute(“Description”).Value : string.Empty,
PermissionLevel = sharePointGroup.Attributes(“PermissionLevel”).Any() ? sharePointGroup.Attribute(“PermissionLevel”).Value : null,
Users = sharePointGroup.Elements(“User”).Any() ? sharePointGroup.Elements(“User”) : null,
AllowMembersEditMembership = sharePointGroup.Attributes(“AllowMembersEditMembership”).Any() ? Convert.ToBoolean(sharePointGroup.Attribute(“AllowMembersEditMembership”).Value) : false,
AllowRequestToJoinLeave = sharePointGroup.Attributes(“AllowRequestToJoinLeave”).Any() ? Convert.ToBoolean(sharePointGroup.Attribute(“AllowRequestToJoinLeave”).Value) : false,
AutoAcceptRequestToJoinLeave = sharePointGroup.Attributes(“AutoAcceptRequestToJoinLeave”).Any() ? Convert.ToBoolean(sharePointGroup.Attribute(“AutoAcceptRequestToJoinLeave”).Value) : false
};
            // iterate through the groups and create the groups
foreach (var sharePointGroup in groups)
{
// only create the group if it does not exist
if (!ContainsGroup(currentSite.SiteGroups, sharePointGroup.Name))
{
// add the owner to the web site users
if (sharePointGroup.Owner.IndexOf(@”\”) > -1)
{
SPUser owner = currentSite.EnsureUser(sharePointGroup.Owner);
currentSite.SiteGroups.Add(sharePointGroup.Name, owner, owner, sharePointGroup.Description);
}
else
{
SPMember owner = currentSite.SiteGroups[sharePointGroup.Owner];
currentSite.SiteGroups.Add(sharePointGroup.Name, owner, currentSite.CurrentUser, sharePointGroup.Description);
}
                    SetRoleDefinitionBinding(sharePointGroup.Name, currentSite, sharePointGroup.PermissionLevel);
                    if (sharePointGroup.AllowMembersEditMembership || sharePointGroup.AllowRequestToJoinLeave || sharePointGroup.AutoAcceptRequestToJoinLeave)
{
SPGroup group = currentSite.SiteGroups[sharePointGroup.Name];
if (sharePointGroup.AllowMembersEditMembership)
group.AllowMembersEditMembership = true;
                        if (sharePointGroup.AllowRequestToJoinLeave)
group.AllowRequestToJoinLeave = true;
                        if (sharePointGroup.AutoAcceptRequestToJoinLeave)
group.AutoAcceptRequestToJoinLeave = true;
                        group.Update();
}
}
                // add the users to the group
AddUsersToGroup(sharePointGroup.Name, sharePointGroup.Users, currentSite);
            }
        }
and the XML configuration
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Groups>
<Group Name=”Admins” Owner=”domain\dave” AllowMembersEditMembership=”true” Description=”Set of admin users who control membership of the Bulk Processing group” PermissionLevel=”Read”>
<User Name=”domain\dave” />
</Group>
<Group Name=”My Security Group” Owner=”Admins” Description=”description goes here” PermissionLevel=”Read”>
<User Name=”domain\dave” />
</Group>
</Groups>

Written by Dave Hunter

07 Jul 2011 at 3:51 PM

Tip: STSADM Exporting 17KB File

leave a comment »

When exporting a site in SharePoint 2007 using STSADM, you may get a .CMP file 17KB in size. This will be because the user who is running STSADM doesn’t have access to the site. If you give the user permissions to the site, you will export the site successfully.

Always run STSADM as a user with a site collection owner rights on the target site.

Written by Dave Hunter

12 Jun 2011 at 6:40 PM

Posted in SharePoint 2007

SPS 2003 upgrade to MOSS 2007

leave a comment »

I’ve successfully completed several migrations from SharePoint 2003 to MOSS 2007 with sites that have had various degrees of customisations. Mainly these have used the database migration approach. This was due to minimising the amount of downtime and to new hardware requirements.

Microsoft have whitepapers and information on technet for upgrading to SharePoint 2007, for more information go here http://technet2.microsoft.com/Office/en-us/library/601874ea-86c9-4611-bdaf-abe17bbb68161033.mspx?mfr=true

Planning is definitely the most important stage of the upgrade process. You need to choose the correct approach. The approach maybe obvious but you need to weigh up the pros and cons of each approach before deciding.

Choosing the upgrade approach http://technet2.microsoft.com/Office/en-us/library/53b8a28b-43c4-43aa-8854-d72d9b7b59c41033.mspx?mfr=true

Using the database migration I was able to stagger the upgrade for each of the site collections, so that user acceptance testing can be carried out and the migrated site approved by the stake holders. This also meant I was in full control of what content was to be migrated and at which point in time, reducing the impact on the end users.

One of the issues with the database migration is that you are actually adding the old SharePoint 2003 content database within the new SharePoint 2007 web application. This means you will now have two content databases for each site collection you migrate. You can specify site limits on the content databases in central administration so that the new sites will use the new database, but you will still have two databases to backup and manage etc.

The diagram below illustrates the normal process.

A way around this is to migrate the SharePoint 2003 site collection to a temporary web application. Once this has been completed and the target audience are happy the content has come across you can then setup content deployment to push the content from the temporary web application to the new site.

The diagram below illustrates this process.

Written by Dave Hunter

13 Jul 2007 at 1:20 PM

Posted in SharePoint 2007

SharePoint 2007 Support Knowledge Base

leave a comment »

It’s worthwhile to keep an eye on this page http://support.microsoft.com/search/default.aspx?catalog=LCID%3d2057&spid=11373&query=&adv=&mode=s&cat=False&range=1-180 it lists workarounds and support information for SharePoint 2007.

Written by Dave Hunter

18 Jun 2007 at 2:35 PM

Posted in SharePoint 2007

Follow

Get every new post delivered to your Inbox.