Zac Mullett Engineering Services
Weblog

Archive for the ‘SharePoint’ Category

Determining web part user permissions on a Web Part Page

Monday, March 23rd, 2009

A web part I’m creating must display an option to save settings, but only for designer (or administrator) users.

Web Part Page documents are SPListItem objects internally, even though SharePoint makes a distinction between document and list libraries in the user interface. I couldn’t find a path through the object model of finding this SPListItem that my web part instance was a part of. Instead I accessed the item via the current URL and a reference to the context’s SPWeb.

A typical problem with assessing permissions (or roles) for a non-administrative user is that SharePoint savagely denies access to it. Try/catch blocks can be ineffective here, with ASP.NET deciding to redirect to the ‘Access denied’ page. Depending on what you need to do, there are methods involving simple impersonation or more convoluted techniques.

Thankfully I found a peace-loving property .AllRolesForCurrentUser that accurately returns the item-level roles for the current user, regardless of their permissions level.

(more…)

DataFormWebPart’s sensitivity to XSLT parameter tag placement

Monday, February 23rd, 2009

While customising the XSLT of a DataFormWebPart I found a discrepancy between design-time and run-time interpretation of a template tag implementing param and variable tags. Placing the <xsl:param> tags first is important.

(more…)

Improving readability of multi-line text columns in display view

Friday, February 20th, 2009

SharePoint users have a tendency to create All Items views containing almost every column in their lists. In cases like these, the readability is often poor, and SharePoint gives users no ability to format the cells appropriately (such as text alignment, column width, etc). One case where this is most disrupting is for multi-line text columns. Single line text columns have a CSS width setting, but multi-line columns depend on the user including a sensible amount of columns to view. The image below illustrates this circumstance.

Squashed multi-line text column

(more…)

Custom rendering of a field’s value in list display mode

Wednesday, January 21st, 2009

In developing the Digital Signature Field for SharePoint I wanted to add a graphic to clearly display the current state of the signature. Is the signature old, new or invalid? A coloured tick can convey this intuitively while economising on size.

Controlling the rendering of a custom field’s value in most display modes is straight-forward through overrides to the SPField method GetFieldValueAsHtml(object) and the Render() methods of BaseFieldControl.  When it came to rendering the value on the list display (i.e. AllItems.aspx) I found that SharePoint limited me to doing this through the RenderPattern element in the field type definition XML, with the caveat that any values, properties or calculations be limited to the CAML View Schema elements. The MSDN documentation on Patterns of Custom Field Rendering hints that a DisplayTemplate specification will let you gain control of the display mode, including the list display. After messing around for a while I felt quite confident that it didn’t include the list display mode.

Some Googling later, I found someone who had bent the rules a little to achieve complete control over display list value rendering. This IconSet custom calculated field project uses a custom RenderPattern to generate a script reference to a custom aspx page that dynamically renders some document.write(…) code that then renders HTML. Values necessary to identifying which item and field are supplied by the CAML and passed by URL parameters.

(more…)