Richie H’s Weblog

Sharepoint and Stuff

Archive for February, 2008

User Profile Property

Posted by richieh77 on February 29, 2008

Creating Properties

One of the requirements when moving from Plumtree to Sharepoint was the ability to store data which wasn’t contained within the users AD profile in the Portal.

In Plumtree this was quite straightforward and in Sharepoint it’s supposed to be quite easy too.

Simply go to the SSP and select User Profile and Properties link

Towards the bottom is the Add Profile Property link.
Selecting this will allow you to configure the property, it’s internal and display name, content type etc.

The important part for me was the replicable setting.
This allows you to push the value from this property down to all Site Collections.

The display setting is also important as this controls which sections this property appears in.

Towards the bottom you can specify an existing Data Store to get the property data from

The various other settings should be self explanatory.

You will need to have the content db marked as Ready and wait for the Profile Synchronization job to run before the properties appear

Editing

When editing properties there are 3 main sections.

  • Within the SSP
  • Within the Site Collection
  • On the users My Sites

The SSP is obviously a no no as users will not have access to this.
The Site Collection doesn’t allow you to update fields even though this is where the My Settings and the Edit Item links take you.
The only other place is My Sites.  It is possible to edit a user profile without having an actual My Site created.  It’s little known that within the UserDisp.aspx page, there is a redirect control.  If you have specified a My Site location in the Portal Connection field.  Then all traffic will be routed away from the UserDisp.aspx to the users Profile Page on their My Site.

This is great, except that

  • You might want to be connected to another Portal
  • You may have many Site Collections and this will be a pain
  • You don’t want the My Site Portal name appearing in the site navigation

To work around this you will need to use a feature which will apply a delegate control

This is as simple as creating a feature with an Elements file and use the control element with an ID of ProfileRedirection(used in the UserDisp page) and specifying an ascx page location.  You may also specify a sequence to ensure yours appears above any others

The ASCX page will be called each time the page is loaded.  This means you are not modifying Sharepoint central files.  Particularly important when sharing hardware or paranoid about patching.

In our ASCX we simply check the URL, if it starts with a certain address we redirect, otherwise we don’t

To obtain the URL of the My Site, check out my article over here

This article is useful, and has some good links http://blah.winsmarts.com/2007-7-SharePoint_2007__All_you_ever_wanted_to_know_about_User_Profiles.aspx

Posted in Sharepoint | Tagged: , , , , , , , | Leave a Comment »

Time zone Mayhem

Posted by richieh77 on February 27, 2008

So the other day, there I was minding my own business, when the request for a web part that showed the current Share Price for the US and GMT arrives on my desk.

No problem I think we have the source feed and it provides the information with the last updated date in GMT.  Unfortunately they want the FTSE price in GMT and the NYSE in EST.  Converting times accurately between time zones on a server with a differing time zone to the required 1 has been a notorious headache especially when you factor in daylight saving time.

This has been made easier with .NET 3X TimeZoneInformation class but I am not coding in .NET 3.x for Sharepoint were using 2.0, but I did find a Sharepoint equivalent.

The final solution was to store the time in UTC and then use the SPRegionalSettings.GlobalTimeZoneSettings[].UTCToLocalTime to convert the time to the appropriate time.

So for a date object like 26-FEB-08 16:56 GMT

Simply myDT=DateTime.Parse(“26-FEB-08 16:56 GMT”);
myUniversalDT=myDT.ToUniversalTime();
string estTime=SPRegionalSettings.GlobalTimeZones[14].UTCToLocalTime(myUniversalDT).ToString();

string gmtTime=SPRegionalSettings.GlobalTimeZones[28].UTCToLocalTime(myUniversalDT).ToString();

So there you go, this uses out of the box Sharepoint 3.0 functionality to convert UTC times to EST(14) and GMT(28) obviously this could be expanded to for loop through the objects and then you wouldn’t need to hard code the indexes.

Posted in Sharepoint | Tagged: , , , , , | Leave a Comment »

Creating Site Collections and Groups

Posted by richieh77 on February 9, 2008

Ok, so one of the jobs I needed to do was automatically create a Site Collection and then create the members, owners and visitors groups.

The first job is to get hold of the web application

SPWebApplication spWA= SPWebApplication.Lookup(new Uri(http://mySite));

Next you can use the Sites collection to create the appropriate Site Collection
The new site collections URL can either be in the format mySiteCollection or managedpath/mySiteCollection

int32 lcid=1033;
string template="STS#2" //Get the one you want
here
SPSite spS=spWA.Sites.Add(url,"SiteName","SiteDescription",lcid,template,"\\domain\ownerloginname","Owner Name",
myemail@here.com)
There are a number of Add methods allowing you to configure owners, secondary owners, and config databases.  Full list here

Once you have done this you will need to add the groups.
This is quite straight forward using the new site collections rootweb property and inturn the SiteGrpups collection

SPWeb spW=spS.rootWeb;

The trick now is to add the group.  The issue here is that you will need an SPMember object which is either SPGroup or SPUser for the owner object.
The problem I encountered is that unless the user is part of the Root Web then they can’t be added as a Group owner.  The group will half create and the API will not throw an Exception.  What you will end up with is a Link in the Site Groups area of teh Site Collection, that errors when clicked. Also the SiteGroups count property will not reflect the new group, but you will not be able to add a group with the same name without receiving a name already exists exception

There are several ways to get a user object.  One involves a straight spW.SiteUsers.Add(…… lots of data)

the other uses the Microsoft.Office.Workflow.Utility and generates a Contact, then uses this to get the actual user object. 

Contact contact=Contact.FromName(userloginname,spW);
if(contact.PrincipalID < 0){
     //this actually adds the user to the site collection users list
     SPPrincipal p=contact.GetPrincipal(spW);
}
SPUser owner=spW.SiteUsers[contact.LoginName];
spW.SiteGroups.Add(spW.Title + " Owners",owner,null,"This is the default owners group")
SPGroup grpOwner=spW.SiteGroups[spW.Title + " Owners"];
spW.AssociatedOwnerGroup=grpOwner
//Repeat for other groups

Finally set the group permissions

SPRoleDefinitionCollection roleDef=spW.RoleDefinitions;
SPRoleAssignmentCollection roleAssigns=spW.RoleAssignments;
SPRoleAssignment roleAssign = new SPRoleAssignment(grpOwner);
SPRoleDefinitionBindingCollection definitions=roleAssign.RoleDefinitionBindings;
definitions.Add(roleDef["Full Control"]); //Could be Contribute or Read
roleAssigns.Add(roleAssign);
//Repeat for other groups
spW.Update();

Posted in Sharepoint | Tagged: , , , , , , , , , , , , , , | 3 Comments »

 
Follow

Get every new post delivered to your Inbox.