Category Archives: SharePoint 2007

Displaying List Attachments in Custom List Forms

As some of you may already know, there is a problem with the SharePoint List attachments functionality if you use Custom List Forms: you lose it all. If you create a custom NewForm.aspx or EditForm.aspx, with a custom List Form control, the ability to add or delete attachments to a list item disappears.

Marc Davis has described a workaround on his Blog here, which is not supported by Microsoft, but works well.

Recently I encountered a situation at a customer’s site, where only the DispForm.aspx had to be modified, because of some required re-formatting of list item values. I figured I didn’t have to go through the whole process described by Marc, since all I wanted back was the functionality to display the list item attachments, not the upload and delete functionality (the NewForm.aspx and EditForm.aspx didn’t need any customization, and these pages have the proper attachment functionality in place).

This turned out to be quite easy: you can use the SharePoint control AttachmentsField.

Here’s the code I added in the dvt_1.rowview XSL template, part of the DataFormWebPart that SharePoint Designer creates for you when you insert a Custom List Form:

      <td width=”190px” valign=”top” class=”ms-formlabel”>
       <h3 class=”ms-standardheader”>
      <td width=”400px” valign=”top” class=”ms-formbody”>
       <SharePoint:AttachmentsField ControlMode=”Display” FieldName=”Attachments” runat=”server” Visible=”true”/>

That’s it! Your list item attachements are back in your custom DispForm.aspx

P.S.: Of course, you should never edit your DispForm.aspx directly, but always leave it intact and create a new aspx page, based on the DispForm.aspx.

Update 16-09-2008:

I found out today, that Microsoft has released a knowledge base article a few days ago about this issue. It seems they have solved the issue regarding the adding and deleting of attachments in the Infrastructure Update for SharePoint. You still have to do some XSL editing, but hey, since you are creating a custom list form, my guess is you are doing this already. You can find the knowledge base article here:

How to filter data in a Data View Web Part, based on the URL of the Web Part Page

A scenario that we encounter a lot, is where you have a project landing site with individual project sites below. On the landing site you have a SharePoint list with all your projects and on each individual project site, you would like to show the project details from this list of the parent site.

Basically this would mean you would have to add a Data View Web Part on the project site to show data from the Projects list of the parent site, and filter the data is some sort of way to show only the data for the appropriate project. This works quite well of course, but you don’t want your users to have to set that filter every time they create a new project site. So what we would like is to set the filter in the project site template.

Of course you never know beforehand what actual value to filter the list data on, so we have to create a dynamic filter solution. My solution is to filter the list data in the Data View Web Part using the URL of the project site. This means that people creating a project site, should use the project name or project number (or any other unique column value you use in your Projects list) as the URL of the project site. In my example, the URL of the projects landing site is http://servername/sites/projectnet.

I assume you know how to add a Data View Web Part to the default.aspx page with SharePoint Designer. You’ll also need SharePoint Designer to make the modifications I suggest below.

  1. From the “Common Data View Tasks” menu, click “Parameters.”, click “New Parameter”, type “CurrentURL” as the Parameter Name, choose “Server Variable” as the Parameter Source, and type “URL” as the Server Variable Name.


  2. From the “Common Data View Tasks” menu, click “Filter:”, enable “Add XSLT Filtering”, and click “Edit.”.


  3. Enter the following XPath expression:


    Where @ProjectName is the name of the column from your Projects list you would like to filter on, and /projectnet/ is the part of the URL preceding your project site URL (probably your project landing site).

Save your site as a SharePoint Site Template and every new project site should automatically show the project details on its default.aspx page.