Create a Related Documents Data View

Customizing the Budgeting and Tracking Multiple Projects Template

This is the final product of this blog… a related documents data view that functions and looks like the related tasks, issues and milestones on the
Budgeting and Tracking Multiple Projects Template.

At my organization, we have found the Budgeting and Tracking Multiple Projects Template extremely useful. For those of you have not seen this template I urge you to go to and view an example of this handy template. The link is in the left nav 2cnd one after the heading Template Type: Server Admin.

In a nutshell the template allows you to track all you projects as you normally would. When you click on a detail view of the project, you also get a related tasks, related issues and related milestones data views on the same page. Any tasks, issues or milestones you add on this page will be associated with that particular project and will rollup onto a nice looking dashboard.

However… like anything, SharePoint gets you 95% there and leaves you to your own devices to accomplish the last 10 feet.

I was asked by a business user to add a related documents view. Made sense to me, so now you have all your tasks, issues, milestones and documents on one convenient page. Perhaps people would like to add a related links or related announcements or calendar items, so I set out to figure a way to add these items with one goal in mind, make a no .net code solution that a user with SharePoint designer could do. Here is the fruit of my labors.

First you must have the Budgeting and Tracking Multiple Projects Template. It is one of the Fantastic 40 Microsoft templates for SharePoint. If you don’t already have it, you will need a farm administrator to install it for you. If you have these permissions and want to do it, here are the templates and instructions.

Second you must have SharePoint Designer and the permissions to use it, other than that you are good to go!

Finally, you can do this on the detail view of any list, not just the above template.

Step 1: Create a new Document Library
I called mine Project Documents, call yours whatever you would like. Go into Settings then Advanced Settings and click on Yes to Allow management of content types. This allows you to add a new column to the Document Library Content type.

Step 2: Add a new lookup column to the Document Library
It makes no difference what you call this field, but I called mine Project. You will want to point it at the Item column on the Projects List. Now go back into your new library and add a few documents and select a couple of projects in your newly created lookup column that they belong to.

Step 3: Open up the DispForm.aspx page in the Lists-Projects Directory
Make a small text edit to make sure you have the right page, and now go get a cup of coffee or another favorite beverage, because the next part is a little complex if you’re not used to looking at code.

Step 4: Click below the Related Milestones Data View and insert a new Data View
In your data source, choose your document library you just made and pick the fields you would like to display. I recommend the minimum of the fields “item” and “url path”

Step 5: Add a Query string parameter called “projectname”
Click on the arrow in the data view box and select parameters from the menu Click “New Parameter” Pick “Query string” for Parameter Source and “projectname” for Query String variable.

Now click on the arrow again and this time select Filter.  Pick the Name (for use in forms) field when it equals [projectname].

Step 6: Add a div tag around the title
The title of the page is the name of the item you are looking at in detail. For example if you click on the Project called “Upgrade Servers” The title of the detail page will be at the top of the page – Projects List: Upgrade Servers. If we select this title in design view, we will see that the this title field is an asp tag called

<sharepoint:listitemproperty id=”ID_ItemProperty” runat=”server” maxlength=”40″></sharepoint:listitemproperty>

Add a div tag around this asp tag like this:

<span style="font-size:x-small;">&lt;div id="projectname" style="display:inline"&gt;
<div id="projectname" style="display:inline">
<SharePoint:ListItemProperty id="ID_ItemProperty" MaxLength=40 runat="server"/>

This div tag allows you to grab the title of the item you want to filter your related documents on.

Step 7: Add the following Javascript Code
Add this code directly after an existing javascript code snippet on the dispForm.aspx page

<script type="text/javascript">

function querySt(ji) 
	hu =;
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) 
		ft = gy&#91;i&#93;.split("=");
		if (ft&#91;0&#93; == ji) 
		return ft&#91;1&#93;;
var projectname = querySt("projectname");
var checked = querySt("projectname");
var url=window.location
if (!projectname && !checked)
	window.location = url


Now select a project on the main page.  Only the documents that have that project listed in the lookup field Project, should appear.  Test to make sure it works

Step 8: Fix up the view to look the way you want
This is perhaps the most tedious and time consuming part of adding a related list, getting it to look the way you want.

Select the table, click on the arrow for the data view and click edit columns. I used the columns Item, Modified and Modified by.

Find the following in the related documents view
xsl:value-of select=”@Title”/>
and replace with

<a href="{@FileRef}">
<xsl:value-of select="@Title"/>

This will display the item as a link to the document.

Make two new table rows right after the start of the table and add the title “Related Documents” to the second row.

<table border="0" width="100%" cellpadding="2" cellspacing="0">
<td class="ms-WPHeader" colspan="99">
<xsl:text xmlns:ddwrt="" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp; </xsl:text>

<td class="ms-WPHeader" colspan="99">
<h3 class="ms-standardheader ms-WPTitle">Related Documents</h3></td>

Add the following code right before the closing table tag for the “upload new document link”.

<tr valign="top">
<td colspan="99" class="ms-vh">
<a href="Enter the url of your new item for the library here">
Upload a new Document...



33 Responses to Create a Related Documents Data View

  1. Mick Brown says:

    Nice one Bryon, I found this while looking for the google charts api stuff. I’ve been looking for this info for a while. Much appreciated

  2. Robert McQuaig says:

    For some reason i cant get this to work…i followed step by step, but to no avail…no errors, but nothing is pulling back as ‘related’…i badly need this to work but cant figure out what im doing wrong?

    • wyly says:

      I have found that WordPress changes double quotes and a few other characters to an equivalent looking special characters that break the javascript. I have now revamped the code to copy/paste inside the code boxes so it should now work.

  3. Robert McQuaig says:

    This worked beautifully! Using the above method i have been able to also create a ‘related contacts’ view to show information such as vendors, etc. that are working on the project as well. My ‘project contacts’ list has a multiple value column for ‘projects’, as we could use the same vendor on different projects and this method above had no problem handling this as well..

    thanks so much for this! i will be recommending…

  4. […] Create a Related Documents Data View « Codeless Solutions for SharePoint […]

  5. wyly says:

    The only reason I can think of John is that the code that reloads the page is not seeing this in the url: checked=1
    at the very end of the url. Do you see that? It prevents the page from reloading after the first time (the first reload puts the document name in the url so the related document will filter the list.)

  6. John says:

    Thanks for the info, don’t know why, but after several tries I got it fixed by just retyping the checked=1, who knows. If runs but returns no records. I think I figured out the issue. In step 2 I have no Item Column in the Project List. I installed another copy of the template and no go either. I have Project Name, Category, Status. etc columns but no Item column. Am I overlooking something?

  7. Tenorman says:


    This is great functionality. Thank you.

    I could not get it to work by following the instructions. This might save someone else some time. I could see that the parameter was working in the URL but my page would not display any documents in the dataview. I step 5 I changed the filter from “Name (for use in forms” to the field I created in Step 2 , which in my case, is called “Project.”

    After that – everything displayed as advertised.

  8. Christy says:

    Hi all,
    how do you get the a new document link ?

    • wyly says:


      First, go to the library you want to create the new document on.

      Next, click on “upload”

      You are now at the upload page. Copy and paste the url of this page into your new document link. that way when someone clicks on new document they will be taken to this upload page for that list.


  9. Christy says:

    Hi Wyly,
    I Tried this … and bring me error message: “This web part does not have a valid xlst stylsheet: error: a name was started with an invalid character. upload a new document…..

    ../_layouts/Upload.aspx?List={$ListID}}&RootFolder=[http://document library]&source=[http://default page]

  10. Kathrin says:

    Sounds like something I did so far with a lot manual changes. So looking forward to see this in live here 🙂
    I tried it so far without downloading the Microsoft Templates and it worked fine until Step 7 “Add this code directly after an existing javascript code…”
    I don’t have any javascript code in my dispForm.aspx page.
    And without this code nothing is working anymore.

    So could somebody PLEASE pass me on the javascript code which has been in the dispForm page before?

  11. wyly says:


    Did you try pasting the code at the end of the page? I put the paste the javascript at this point to insure people didn’t place it in there xmlt code and jack up the page.

    I’m interested in learning if this works without the template

  12. Scott S says:

    Wondering if anyone could share their correctly modified DispForm.aspx page. I get errors regarding the code and not sure if it is the way it is formatted in this posting or not.

  13. soy says:

    thank you thank you thank you.. Jesus, I have been on the phone with Microsoft for 2.5 hours as well as another 4 hours of trying to figure this out on my own. Not even the SharePoint tech understood how to do this, I had to show them this tutorial once I’d fixed it because they wanted to know.

  14. Matt says:

    I am also getting the javascript error on step 7. The error in sharepoint designer reads:

    This web part does not have a valid XSLT stylesheet:
    Error: A name was started with an invalid character. gy = hu.split(“&”);

    I pasted the javascript after the section of the new webpart. (Around like 340) I’ve tried putting it in several other areas with no luck.

  15. Matt says:

    I solved my problem. Here’s what i did:

    Step 5:

    For the filter, instead of using Name (for use in forms) i chose Project as the field name.

    Step 7: skipped completely.

    To the author, what does the script in step 7 do other than only show you documents that are linked to the project?

    • wyly says:

      Step 7 grabs the title of the page puts it into a querystring and reloads the page so the querystring filter can work like it is supposed to. Perhaps you found a shortcut… very intersting

      Bryon Wyly

  16. Matt says:

    Sharepoint 2010 makes this so much easier. I was pissed off when i found out 2010 doesn’t include a template similar to the Budgeting and Tracking Multiple Projects template that 2007 provided. I set out to create me my own. All i did was create a blank site and the proper lists. Added the lookup fields to each list (and document library). Sharepoint 2010 provides a nice new “Insert related list” function that adds the related tasks, milestones, documents etc to each page. Its sooooo easy. Here’s a blog post i found that showed me how to do it:

  17. Joel says:

    I cannot get this to work, Step 6 gives me the error:
    Span cannot contain div.

    • Joel says:

      Anybody have a copy of their DispForm.aspx that they could share? I would really appreciate it.



      • wyly says:


        You are not the first to ask for this. I have been working with 2010 for the last couple of months. When i get a chance I will recreate this and display the page code.


    • wyly says:

      Sounds like you may have placed the code inside a span tag. Try pasting it directly after a closing script tag

  18. Beau says:


    Also I don’t seem to have the “Item” field in the template?

    Many thanks

    • Beau says:

      Hi Bryon,

      Me again, just wanted to say thanks for this article.

      I have finaly got it to work.

      One question I have though is that wehn the page loads it seems to then reload, it means when I click the back button on my browser I just get the same page again and I have to click back twice to get back to my list. Is the way it should be or have I done something wrong?

      Many thanks

      • wyly says:


        I’m glad you got it to work. The way the javascript code works is that it it grabs the title on page load then reloads the same page with the title in the querystring. This allows the querystring filter to grab the title and filter the view to show only the documents that relate to that Project. Kind of a hack, so you would have to hit the back button twice to go back to the previous page.

  19. Adam says:

    I cannot get this to work. I have tried everything. I get the error:

    This web part does not have a valid XSLT stylesheet:
    Error: A name was started with an invalid character. gy = hu.split(“&”);

    I have tried what Matt suggested by skipping step 7 entirely yet still nothing shows up.

    Does anyone else have any ideas. Can we enter the j script code in the CEWP?

  20. asembler says:

    While this is exactly what I was looking for I couldn’t get this solution to work. Besides this is not really a code-less solution since you are using javascript, and while it’s not a .net code, it’s still code.

    • wyly says:

      Pasting javascript into a content editor web-part is a far cry from custom .net web parts. Maybe I can come up with a better slogan to explain that fact. How about Coderless Solutions? 🙂

  21. Sev says:


    Special characters in the project name are unable to display related fields. This solution works great with the exception of any projectname that contains ‘ or &. Is there any fix for this?

  22. SK says:

    Hi Wyly,
    Thank you very much for sharing this wonderful article.

    I’am working on a project with similar functionality to achieve in Sharepoint2010, all my lists and libraries default forms are customized using infopath2010. Couldn’t make it to work as the one mentioned above, can someone help please.
    Many Thanks,

  23. Lora says:

    It’s a shame you don’t have a donate button! I’d certainly donate to this brilliant blog! I guess for now i’ll settle for bookmarking and adding
    your RSS feed to my Google account. I look forward to new updates and will share this
    website with my Facebook group. Talk soon!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: