Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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()
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top