Posts tagged Web Parts

Adding a related filtered list to a Sharepoint list’s Display Form (dispform.aspx)

Whilst customising one of the Microsoft Sharepoint application templates we needed to work out how to add a view of a list that was related to the item that was being shown in dispform.aspx.

To achieve this:

Add a DataViewWebPart (DVWP) in Sharepoint Designer

Set the DataSource of the DVWP to the related list you want to filter

Add a QueryStringParameter to the DVWP’s <SharePoint:SPDataSource> ==> <SelectParameters> as follows:

<asp:QueryStringParameter QueryStringField=”ID” name=”0″></asp:QueryStringParameter>

Update the SelectCommand of the <Sharepoint:SPDataSource> as follows:

SelectCommand=”&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=’Meeting’ Type=’Integer’ LookupId=’True’&gt;&lt;/FieldRef&gt;&lt;Value Type=’Integer’&gt;{0}&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;”

This translates into the following CAML query:

SelectCommand=”<View><Query><Where><Eq><FieldRef Name=’Meeting’ Type=’Integer’ LookupId=’True’></FieldRef><Value Type=’Integer’>{0}</Value></Eq></Where></Query></View>”

The LookupID=’True’ parameter seems to make the query use the lookup fields List ID value.

Render Content Query Web Part output as UL and OL lists rather than tables

The Content Query Web Part (CQWP) is an extremely powerful web part used for displaying content that can be pulled from multiple sites. However the default HTML rendered by the CQWP is full of nasty tables. A requirement was to use the cross site querying benefits of the CQWP but to be able to render the output from it as unordered (UL) lists. Lists have a number of benefits including accessibility, semantic correctness and the ability to more easily target with CSS / javascript.

Sharepoint uses XSL style sheets to sculpt the HTML that is rendered by the Content Query Web Part (CQWP).  We therefore need the web part instance to use modified XSL style sheets.

More >

Sharepoint search – Create an ‘Alert Me’ on individual search results

The default MOSS search results page in a Sharepoint search center site allows the user to create an alert on a set of search results. It does not however give the user the ability to create alerts on individual items in the search results.

The following steps outline the process to add an ‘Alert Me’ link to each individual search result.

The ‘New Alert’ screen is a OOB Sharepoint Application page that takes the following as querystring parameters

  • the GUID of the list the document belongs to
  • the integer ID of the item in the list

The main steps to enable alerts on individual search results are:

  • Ensure the Sharepoint ID column is added to the SSP’s Managed Metadata properties.
  • Make sure this column is selected in the core search results web part data settings.
  • Edit the XSL to write out a hyperlink to a custom application page. The link must have the ID of the list item and the URL of the item added as querystring parameters.
  • Write a custom application page that redirects to the OOB application page located at /_layouts/SubNew.aspx and pass it the appropriate paramters in the querystring.

More >

Create flexible web parts with web part editor properties that hold xml configuration elements

One of the design goals when creating web parts is to make the web part reusable across a number of site collections and web applications where each site administrator may have slightly differing requirements.

To a degree this is achieved by defining web part properties that appear in the web part editor that enable the user to use standard web controls such as textboxes, radio button lists and drop down lists to set the web parts configuration options.

There may be times however where more complex data storage requirements are required for configuration and this is where XML can help by configuring a web part property to store XML which can be parsed and manipulated by the web parts code. More >

Sharepoint web part to enable user to update their AD profile

I have come across the Nomine AD User Editor on Codeplex and found it to be an excellent free web part that enables a user to be able to update their own Active Directory profile. The web part lets the site owner edit the AD fields that appear on the form by using a simple XML configuration file.  The web part supports the following form elements:

  • Textbox
  • Drop down list
  • Listbox
  • People Picker
  • Date Picker (with Calendar)

There are a couple of gotchas to lookout for when using it.

  1. By default it lets the user search Active Directory and edit any user profile so when configuring the web part for a user to update their own active directory profile make sure to:
    • Tick ‘Edit Current User Only’.
    • Untick ‘Allow Editing In Personal Mode’ or else the user will be able to edit their personal view of the web part
    • Nomine AD User Editor Configuration

      Nomine AD User Editor Configuration

  2. Create a new web application specifically for deploying this web part to. This is because the web part is activated as a feature at Site Collection level and if you deploy to another application such as an intranet then any site collection administrators on any site collection in the application will be able to add the web part to their pages and if they do they will doubtless forget / be unaware of the two previous configuration steps outlined above and you will then have any user being able to update any other users details.

All in all this is a great web part that dynamically creates the edit user form using information from the xml configuration.

A wish list for the web part would be to

  • Support encrypted passwords in the .config file so that the details of the AD account were not exposed in free text.
  • Give a ‘Details updated successfully’ type prompt after the user submits the form.
  • Make the ‘Edit Current User Only’ property read only if editing the web part in personal mode.