Tuesday, July 17, 2007

Internet Explorer Default XSL

To view the default XSL used by IE, browse to res://msxml.dll/DEFAULTSS.xsl in Interner Explorer. This works in versions of IE prior to IE9 - I have not found an equivalent for IE9

Monday, July 9, 2007

MOSS Install - Tips from an MS Field Engineer

Tips from a Microsoft premier field engineer on how to achieve a "... less painful experience ..." when faced with a MOSS install - http://sharepoint.microsoft.com/blogs/fromthefield/Lists/Posts/Post.aspx?ID=9

(and here's another useful post on configuring Alternate Access Mappings)

Sunday, July 8, 2007

Calling a Custom Javascript Function on Page Load

A simple way to add a custom Javascript function to the list of scripts that run at page load is as follows:
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("YourFunctionName");
</script>

Thursday, July 5, 2007

Displaying Site Data in a SharePoint Page

To display the name of the current site in a master page or page layout within SharePoint, add the following control to the source of the page:

<SharePointWebControls:ProjectProperty Property="Title" runat="server"/>

This display the title of the site. The ProjectProperty SharePoint Web Control is useful for displaying properties of the current web site. Other fields such as the site description can also be displayed this way

Note that Microsoft must have used the name "project" at some stage for a SharePoint site, given the name of this control and also the name of the site Title and Description settings page (which is prjseng.aspx)

Adding a CSS File Link to a MasterPage

Use the following to add a reference to a stylesheet in a WCM publishing site's Style Library document library:

    <SharePointWebControls:CssRegistration ID="CssRegistration1" 
      name
="<% $SPUrl:~sitecollection/Style Library/style.css %>"
       runat="server"/>

Note that some of the default styles may still override those in the referenced stylesheet, so you may need to add the CSS as the Alternative CSS URL on the "Site Master Page Settings" form

Wednesday, July 4, 2007

Field Controls in a Layout Page not Displayed in Edit Mode

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?

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);
                        
}
                    }
                }
            }
        }