Please upgrade your web browser now. Internet Explorer 6 is no longer supported.
Zac Smith
SharePoint, WSS and MOSS development.
A while back I blogged about how you could use the SPSecurityTrimmedControl to manage the display of content based on user permissions. The PermissionsString is where you specify what permissions the user must have to display the content. Until now I wasn't sure what values you could use, and the SDK although much imporoved wasn't exactly forthcoming. While using a reflector I managed to track down the SPBasePermissions enum which reveals all the possible values.
 
And here they are grouped in the same way you would find them in the SharePoint permissions list:
 
List Permissions
 
Site Permissions
EnumeratePermissions
 
Personal Permissions
 
 
And an example of usage if you are reading this and haven't seen the control in action before:
 
<SharePoint:SPSecurityTrimmedControl PermissionsString="AddAndCustomizePages, ManageLists" runat="server"
    <%-- some content here ... %>
</SharePoint:SPSecurityTrimmedControl>
Categories:

So I have finally jumped on the PowerShell bandwagon and created my first (useful) script. I had a need to migrate a bunch of users from local machine accounts to domain accounts. So I had a look at what stsadm commands were available and noticed enumusers and migrateusers. I figured I would be able to create a little PowerShell script that went through all the users and migrated each one. I did have the advantage of knowing that the logins were the same on the local machine as they were on the domain. A more sophisticated migration might have some xml look-up file to migrate to new login names.

The command .exe -o enumusers -url http://wsstestsite will return an xml string of users from the site http://wsstestsite.
The xml looks something like:

<Users>
  <User>
     <Login>domain\user</Login>
     <Email>user@domain.com</Email>
     <Name>SharePoint User</Name>
  </User>
  <User>
  ...
  ...
</Users>

And the script I wrote looks something like this:

# extract all users into an xml file
[xml] $users = c:\"program files\common files\microsoft shared\web server extensions\12\bin\"stsadm.exe -o enumusers -url http://wsstestsite

#iterate through each user (note the dot notation for accessing nodes)
foreach($login in $users.Users.User)
{
# determine old and new login (using regular .Net string func)
$oldlogin = $login.Login
$newlogin = $login.Login.Replace("LocalMachine", "Domain")

# migrate user
c:\"program files\common files\microsoft shared\web server extensions\12\bin\"stsadm.exe -o migrateuser -oldlogin $oldlogin -newlogin $newlogin
}

So the code basically converts each user login from the machinename\login to domainname\login.
I realise that you could probably write this a lot cleaner and simpler, but it was just thrown together in 15mins and I wasn't too worried about being elegant.

If you haven't had a chance to try out PowerShell I highly recommend you have a look. You can download it from here: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx
There are HEAPS of resources around the web on PowerShell so it's really easy to get started.

Categories:

Although I love the solution framework I do have one gripe. It doesn't remove the web parts deployed to the gallery when the solution is retracted. To address this I have written a little custom code in a feature deactivation event:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
 
// manually delete web parts from the gallery

  using (SPSite site = (SPSite)properties.Feature.Parent)
  {
   
using (SPWeb web = site.OpenWeb()) 
    {
      SPList list = web.Lists["Web Part Gallery"];

      // go through the items in reverse
      for (int i = list.ItemCount -1; i >= 0; i--)
      {
        // delete web parts that have been added
        if (list.Items[i].Name == "Login.webpart")
        {
          list.Items[i].Delete();
        }
     
}
   
}
  }
}

Note that I have written this with 'using' clauses to ensure that the web and site objects are properly disposed of after use. I also iterate through the collection in reverse in case I want to delete many items.

To make the code run I will have to add something like the following to the feature.xml.

ReceiverAssembly="Provoke.UserAdminFeatures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=083c78f3ca84e8af"
ReceiverClass="Provoke.UserAdminFeatures.FeatureActivation"

More details about adding events to features can be found in the WSS SDK here.

Categories:

So if like one of our clients, you failed to upgrade your Beta 2 Tech Refresh MOSS to the RTM version you might find this useful.

  1. The first step is to get the B2TR site functioning again. The MOSS expiration cut off can be tricked by winding back the clock on the server. You might want to communicate with the Infrastructure team about this, and they will likely have some gripes but it is only temporary. After you have set the clock back test the site and make sure it works. You should upgrade MOSS immediately. Do NOT just wind the clock back for a year!
  2. Stop the Windows Timer Service on the server. Otherwise in a couple of hours (probably mid upgrade) the clock will update to the current time. This can be stopped from the services snap-in in administrative tools. It is called Timer Service
  3. Now that the B2TR site is up and running you can perform the upgrade to the RTM version. There are a couple of guides to follow which are accurate and straight forward to follow. Either the Microsoft Guide, or Shane Young's Guide will work. There is also a web cast that demonstrates the process from Bob Fox. I think the most important thing is to backup you're servers before upgrading. The technology wizard can take quite a while to run depending on the sizes of your content databases. So plan for a few hours of outage.
  4. Now it's just a matter of testing to make sure everything works – I would focus on search and any customisations. It should all be fine as the databases and web applications haven't really changed.
  5. If everything works out ok you can set the time back to the current time and turn the Time service back on.

Good luck!

Categories: