I was creating a new page layout associated with a content type that I had just modified (removed some fields and added others). SharePoint Designer showed the edit controls ocrrectly in the layout page.
But when I went to create a new page in the site using this page layout, only some of the field edit controls were displayed on the new page. No errors were displayed on the page, it was just failing to display some of the controls.
Tracked this is to the content types associated with the pages document library. Document libraries keep local copies of content types, so the pages library was storing the old set of fields for the content type I had changed. An important proviso here is that the custom content type that caused the problems is being modified through a feature rather than manually in the site settings pages. Perhaps if I had modified the content type directly rather than through a feature then the changes would have been propagated to the local copy of the content type in the document library?
Wednesday, July 4, 2007
Tuesday, July 3, 2007
Removing User Permissions From a List Item
Programmatically modifying the item-level permissions in a list involves manipulation of the Role Assignments collection for that item.
This example shows how to remove a specific role definition from each of the members of a user collection:
/// <summary>
/// Remove a role definition from each of the members of a user collection for a list item
/// </summary>
/// <param name="item">The List Item</param>
/// <param name="userVals">The collection of users who are to have the role definition removed</param>
/// <param name="def">The role definition to remove</param>
internal static void RemoveRoleDefinitionFromUsers(SPListItem item, SPFieldUserValueCollection userVals, SPRoleDefinition def)
{
if (userVals != null)
{
foreach (SPFieldUserValue userVal in userVals)
{
SPUser user = userVal.User;
SPRoleAssignment role = item.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)user);
if (role != null)
{
if (role.RoleDefinitionBindings.Contains(def))
{
role.RoleDefinitionBindings.Remove(def);
role.Update();
item.SystemUpdate(false);
}
}
}
}
}
This example shows how to remove a specific role definition from each of the members of a user collection:
/// <summary>
/// Remove a role definition from each of the members of a user collection for a list item
/// </summary>
/// <param name="item">The List Item</param>
/// <param name="userVals">The collection of users who are to have the role definition removed</param>
/// <param name="def">The role definition to remove</param>
internal static void RemoveRoleDefinitionFromUsers(SPListItem item, SPFieldUserValueCollection userVals, SPRoleDefinition def)
{
if (userVals != null)
{
foreach (SPFieldUserValue userVal in userVals)
{
SPUser user = userVal.User;
SPRoleAssignment role = item.RoleAssignments.GetAssignmentByPrincipal((SPPrincipal)user);
if (role != null)
{
if (role.RoleDefinitionBindings.Contains(def))
{
role.RoleDefinitionBindings.Remove(def);
role.Update();
item.SystemUpdate(false);
}
}
}
}
}
Thursday, June 28, 2007
Dependencies in Custom SharePoint Permissions
An event handler I have written applies item-level permissions to modified list items - specific users are granted custom permissions.
This was working fine until I enabled versioning on the list manipulated by the handler. After making that change I noticed that the specific users were now seeing the access denied page in SharePoint when attempting to view items with the managed permissions.
The code was assigning SPBasePermissions.EditListItems and SPBasePermissions.ViewListItems rights for the users. After experimenting in the Edit Permissions Level administrative page in the site settings, I noticed that checking certain boxes caused other boxes to be checked - there are clearly some dependencies behind the scenes that should be applied when assigning custom permissions.
The outcome of the experimenting was that with versioning enabled on the list, the view versions permissions was required. Edit rights on an item will be granted to a user by applying the following set of SPBasePermissions to the role definition:
SPBasePermissions.EditListItems SPBasePermissions.ViewListItems SPBasePermissions.OpenItems SPBasePermissions.ViewVersions SPBasePermissions.ViewPages SPBasePermissions.Open
Viewing rights are granted with the same set, minus the EditListItems member.
This was working fine until I enabled versioning on the list manipulated by the handler. After making that change I noticed that the specific users were now seeing the access denied page in SharePoint when attempting to view items with the managed permissions.
The code was assigning SPBasePermissions.EditListItems and SPBasePermissions.ViewListItems rights for the users. After experimenting in the Edit Permissions Level administrative page in the site settings, I noticed that checking certain boxes caused other boxes to be checked - there are clearly some dependencies behind the scenes that should be applied when assigning custom permissions.
The outcome of the experimenting was that with versioning enabled on the list, the view versions permissions was required. Edit rights on an item will be granted to a user by applying the following set of SPBasePermissions to the role definition:
SPBasePermissions.EditListItems SPBasePermissions.ViewListItems SPBasePermissions.OpenItems SPBasePermissions.ViewVersions SPBasePermissions.ViewPages SPBasePermissions.Open
Viewing rights are granted with the same set, minus the EditListItems member.
Wednesday, June 27, 2007
List of HTML Entities
Comprehensive list of HTML entities available at http://www.w3schools.com/tags/ref_entities.asp
Tuesday, June 26, 2007
How to Display the "New" icon against a List Item
To show the standard
SharePoint icon against new list items in a data view web part (or other XSLT web parts), use the following snippet:
<xsl:if test="ddwrt:IfNew(string(@Created))">
<img src="/_layouts/1033/images/new.gif" alt="New" />
</xsl:if>
SharePoint icon against new list items in a data view web part (or other XSLT web parts), use the following snippet:<xsl:if test="ddwrt:IfNew(string(@Created))">
<img src="/_layouts/1033/images/new.gif" alt="New" />
</xsl:if>
Comparing Dates in SharePoint XSL
Here's a way to peform a date comparison in the XSLT definition of a data view web part:
<xsl:if test="number(translate(substring-before(ddwrt:FormatDate(@Date_x0020_Raised ,1053 ,5), ' '), '-', ''))+2 < number(translate(substring-before(ddwrt:TodayIso(), 'T'), '-', ''))">
<img src="_layouts/images/ewr210s.gif" />
</xsl:if>
This compares the date in the "Date Raised" field with the current date, and if the "Date Raised" is more than 2 days ago then an image is displayed.
<xsl:if test="number(translate(substring-before(ddwrt:FormatDate(@Date_x0020_Raised ,1053 ,5), ' '), '-', ''))+2 < number(translate(substring-before(ddwrt:TodayIso(), 'T'), '-', ''))">
<img src="_layouts/images/ewr210s.gif" />
</xsl:if>
This compares the date in the "Date Raised" field with the current date, and if the "Date Raised" is more than 2 days ago then an image is displayed.
Monday, June 25, 2007
Handling Multivalue and Multiselect Field Values in SharePoint
Having written my own regular expression to parse the values from a multiselect lookup field, I then found a post from Mark Arend that offers regular expressions for all the various "decorated" field types in SharePoint (choices, lookup, Person or Group and Hyperlink fields). Very handy!
Subscribe to:
Posts (Atom)