Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to add a group (SPGroup) programmatically. Everything works fine except for one thing. I would like the group's description to include a link to it's site. Similiar to the look-and-feel in a normal Team Site where it says:

enter image description here

So I use the following code:

web.SiteGroups.Add("ts01 Administrators", owner, null, 
  "Use this group to grant people administrative permissions to the SharePoint site: <a href=\"http://ts01\">ts01</a>");

where "owner" is an instantiated, not null SPPrincipal.

The result I get is not the intended one. SharePoint seems to HtmlEncode everything I send in, and rightly so. But when I create a group using the GUI I can include links in the description. So what's the difference? Has anyone encountered this problem?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

Yup, you've found another SharePoint-ism.

You'll need to the add the group like you're doing and then update the item in the SiteUserInfoList. We use the following static method:

public static void UpdateGroupDescription(SPWeb spWeb, SPGroup group, string descriptionString)
{
    SPListItem item = spWeb.SiteUserInfoList.GetItemById(group.ID);
    item[SPBuiltInFieldId.Notes] = descriptionString;
    item.Update();
}

See also, basically the same question on StackOverflow.

share|improve this answer
1  
Wonderful! I was digging through a lot of DLLs using Reflector to see how things actually worked. Pretty ingenious to use a field called Notes to hold a value for Description... –  Björn Stenberg Jan 4 '12 at 16:55

Thank you very much, powershell version which i wrote based on the above sample.

$sharepointShell = "Microsoft.SharePoint.PowerShell"

if ( (Get-PSSnapin -Name $sharepointShell -ErrorAction SilentlyContinue) -eq $null )
{Add-PsSnapin $sharepointShell}
$newSiteTitle = "Title of the Site"
$newSiteURL = "http://domain.com/managedpath/siteurl"

$spWeb = Get-SPWeb -Site $newSiteURL
write-host -ForegroundColor DarkCyan "SPWeb object intialised"

# Owners Group
$ownerGroup = $spWeb.SiteGroups["$spWeb Owners"]
$ownerGroupItem = $spWeb.SiteUserInfoList.GetItemById($ownerGroup.ID)
$ownerGroupItem["Notes"] = "Use this group to grant people full control permissions to the SharePoint site: <a href=""$newSiteURL"">$newSiteTitle</a>"
$ownerGroupItem.Update()
write-host $ownerGroupItem["Notes"] 

#Dispose SPObjects
$spWeb.Dispose()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.