Richie H’s Weblog

Sharepoint and Stuff

Posts Tagged ‘properties’

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 »

Collaboration Server

Posted by richieh77 on January 29, 2008

As part of the migration I have been requested to build a tool that will migrate Collaboration server projects including:

  • Creating a Team Site Site Collection for each Collaboration Server project
  • Migrate all documents, version history, modified date and by, and created date, by
  • Mirror Collaboration Server security roles into appropriate Team Site groups

This particular piece of work has proven quite tricky.
The ability to programmatically set the Modified and Created information proved a real challenge and there are several examples out there on how to do this.

The first thing to remember when trying the alter the meta information is not to use the SPFile object directly.
Instead use the item property of the SPFile.

The SPListItem object provide much more flexibility and the Update methods actually work.

There are 3 main ways to update a given item Update, SystemUpdate and UpdateOverwriteVersion

  • The Update method will work but generates a new version of the item.
  • The SystemUpdate didn’t seem to actually save the change.
  • The UpdateOverwriteVersion did exactly what I needed.

This twinned with
http://msdn2.microsoft.com/en-us/library/ms439259.aspx
Allowed me to set the File information correctly.
Be aware that you MUST set the Created and Modified properties after calling the Add method even though you already passed them in

Folders is a little bit more tricky as you don’t get the option to create a folder object and pass the Author in.
To get around this you should create the folder as above and use the SPFolder item property
Once you have the SPListItem you can set the Created and Modified property.  The property will receive an integer that represent the users ID.

Adding file to list and updating the meta information

The file information is queried and held in a data structure

private struct PlumtreeFile
        {
            public System.DateTime Created;
            public System.DateTime Modified;
            public SPUser ModifiedBy;
            public SPUser CreatedBy;
            public string SourcePath;
            public string TargetPath;
            public string Filename;
        }

SPFolder spFolder = newWeb.GetFolder(newWeb.Url + “/Shared Documents/” + pF.TargetPath);
SPFileCollection spFiles = spFolder.Files;
System.IO.FileStream fs = System.IO.File.OpenRead(pF.SourcePath);
SPFile spF = spFiles.Add(pF.Filename, fs, pF.CreatedBy, pF.ModifiedBy, pF.Created, pF.Modified);
SPListItem spFileItem = spF.Item;
spFileItem["Created"] = pF.Created;
spFileItem["Modified"] = pF.Modified;
spFileItem.UpdateOverwriteVersion();
fs.Close();

Adding a folder and changing it’s meta information, as before the information is held in a data structure

private struct PlumtreeFolder
        {
            public System.DateTime Created;
            public System.DateTime Modified;
            public SPUser CreatedBy;
            public string FolderName;
            public Int32 ParentID;

        }

As the source system didn’t allow version control on folders, we will assume that the Created and Modified By user are the same.
SPFolder spNewFolder = fld.SubFolders.Add(urlPath);
int userID;
userID = newWeb.SiteUsers[pF.CreatedBy.LoginName].ID;
spNewFolder.Item["Created By"] = userID;
spNewFolder.Item["Modified By"] = userID;
spNewFolder.Item["Author"] = userID;
spNewFolder.Item["Modified"] = pF.Modified;
spNewFolder.Item["Created"] = pF.Created;
spNewFolder.Item.Update();

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

 
Follow

Get every new post delivered to your Inbox.