5/23/2009

SharePoint: The List, the Whole List, Nothing but the List

 

SharePoint does not provide a clean way to display or print just a list or library. It only displays the list inside of the master page and that includes all of the navigation, search and graphics.

Here are a few workarounds:

Here is the goal:

The list, the whole list, nothing but the list (and maybe a crumb trail…)

 

 

There are two ways to do what we need. Plan "A" below is "educational" to let you see how it is all done. Plan "B" is the easiest.

After completing the steps below add a link to this new page in Quick Launch, a links list or as a link from some other page.

 

Plan "A" - Create it all in SharePoint Designer

Open SharePoint Designer
Open your site
Right-click in the Folder List on the project root (the first item in the list: http://yoursite)
Select New and ASPX
Rename the file (JustTheList.aspx, etc)

Double click the new file and select the Design view
Select Insert, SharePoint Controls, Web Part
From the Web Parts pane select your list or library and drag it into the Design View of your new page.
Done... ugly, but a working list only page.
Save it and test in a browser (F12 is the shortcut to open the current page)

Now to make it pretty...

We need the Core.css, and optionally the Theme CSS, CSS files linked to this page. You could manually create the <link> tags, but it's easier to copy what you need from the default.master page.

Add this just above the <html> tag:

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Add this somewhere between the <head> and </head> tags:

<SharePoint:CssLink runat="server"/>
<SharePoint:Theme runat="server"/>

If your master page has any custom CSS, add that here too.

Almost there.

Now it looks like a SharePoint list. But it has a title that you may not want and it has the toolbar.

Some properties can be changed from the Design view by right-clicking the web part and selecting Web Part Properties. There you can change most web part properties, except for the view for the list and turning toolbar on or off.

So go ahead and change the title or hide it by setting "Chrome" to none.

To remove the toolbar requires a little code editing.
Display the code view of the page and search for "toolbar".
Change
  Toolbar Type="Standard"
to
  Toolbar Type="None"

Changing the displayed view... Now here's problem. The view is defined by the XSLT embedded in the web part. If you want to pick another view, then it's time for plan "B".

 

Plan "B" - Copy and paste it all...


Open the site in a browser
Go to Site Actions, Create and create a Web Part Page (this is a temporary file, so any name and library will do)
Click Add A Web Part and pick your list or library.
Select Edit, Modify Shared Web part and make all of your customizations.
Click Exit Edit Mode
Open SharePoint Designer
Open your site
Right-click in the Folder List on the project root (the first item in the list: http://yoursite), or select an existing library such as Shared Documents.
Select New and ASPX
Rename the file (JustTheList.aspx, etc)
Double click the new file and select the Design view
In the Folder List browse to the library where you saved the new page and double click the new page to open it
Switch to the Code view and search for "<WebPartPages:ListViewWebPart"
Copy from this start tag to the matching end tag.
Go back to your new page and paste the web part code between the <form> tags.
Save it and test in a browser (F12 is the shortcut to open the current page)

Final cleanup?

  • Add some HTML comments about how you did all of this, or maybe a comment with a link to this artile, so you can fix this up in the future.
  • Find the <title> tags at the top of the page and add a proper title to display at the top of the browser and as the title for Favorites.

And I suppose you want a crumb trail too...
The default crumb trail in the master page looks like this:

<asp:SiteMapPath
    SiteMapProvider="SPContentMapProvider"
    id="ContentMap"
    SkipLinkText=""
    NodeStyle-CssClass="ms-sitemapdirectional"
    runat="server"/>

Strangely this does not display the folders of a library as you drill down using the web part. I tried most of the things I found on the web and none have worked. So as a temporary workaround I created some JavaScript to emulate the crumb trail feature.

JavaScript crumb trail:

<div id="navtrick" class='ms-globalbreadcrumb' style="text-align:left;" ></div>
<script>
fullURL = parent.document.URL
splitURL = fullURL.substring(fullURL.indexOf('?')+1, fullURL.length).split("&")
siteURL = fullURL.substring(0,fullURL.indexOf('?'), fullURL.length)
siteURL = siteURL.substring(0,siteURL.lastIndexOf('/') );
rootURL = fullURL.substring(0,fullURL.indexOf('?')) + "?RootFolder="
path = unescape(splitURL[0].split("=")[1])
folders=path.split("/")
document.all("navtrick").innerHTML = " <a href='" + siteURL + "'>Home</a>"
for (i=1;i<folders.length;i++)
{
  rootURL += "/" + folders[i]
  document.all("navtrick").innerHTML += " &gt; <a href='" + rootURL + "'>" + folders[i] + "</a>"
}
</script>

 

Presented as is… no guarantees… Have fun!

1 comment:

Christophe said...

A couple other options:
- use an iframe to strip out the Master page:
http://pathtosharepoint.wordpress.com/2009/01/22/a-simple-method-to-display-a-list-in-another-site/
- print selected Web content:
http://pathtosharepoint.wordpress.com/2009/04/02/print-selected-web-content/

Christophe

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.