Redirect in SharePoint Using Meta vs JavaScript

This morning I was working on a custom list item display form for a “Tags” list that I created in SharePoint (DispFormCustom.aspx). I replaced the standard display form web part with a data view web part (DVWP). For various reasons that I won’t bother explaining in this post, I needed to create a redirect on this page that included an additional tags parameter in the query string with the @Title of the current list item. For example, if a list item has an ID of “1” and a title of “jquery,” I want the page to redirect from http://server/lists/tags/dispformcustom.aspx?ID=1 to http://server/lists/tags/dispformcustom.aspx?ID=1&tags=jquery.

I didn’t want to use <meta http-equiv="refresh" content="0;url=/{@FileDirRef}/dispformcustom.aspx?ID={@ID}&tags={@Title}" /> because it creates a history entry in the browser. If the user clicks the Back button from the new page, they’ll go back to the page with the redirect and be immediately redirected to the page they were just on. This is bad for the UX. I could extend the time from 0 seconds to 3 seconds or more to give the user more time to click the Back button again, but I don’t think this is a good UX either. I want the redirect to be as transparent as possible. (more…)

Display Events from a SharePoint Calendar Using jQuery and FullCalendar

As part of a large department site redesign project, I wanted to implement a better calendar solution than what MOSS 2007 gives you OOTB. I remembered coming across the FullCalendar jQuery plugin a while back, so I decided to try using it with the calendar on my department’s site. I haven’t tested this in SharePoint 2010, but it should work just fine regardless of the version (just verify all of the column references in case any of them are named differently).

Prepping the Resources

I downloaded the latest FullCalendar package, unzipped the file, and uploaded the CSS and JavaScript files to a document library on my site. I like to use a library called WebResources and add a choice column with options for “CSS,” “Image,” “JavaScript,” and “jQuery” so I can keep track of all of my various resources in one place, with versioning.

Screenshot of FullCalendar Resources in the WebResources Library
I keep all of my resources in a "WebResources" document library grouped by the type of resource.

Once the files were uploaded, I copied the calendar.aspx page and renamed it CalendarCustom.aspx in SharePoint Designer (SPD). Then I switched back to the web UI, went to the calendar settings, and modified the duplicate “Calendar” view so I could rename it and set it as the default (this is the view that will contain our custom calendar). Next I opened that view and hid the default list view web part for the calendar.

The last step in prepping the page was to open it in SPD and add references to the CSS and JavaScript files that the calendar will need just below the <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> tag on the page (you could also put them in a Content Editor Web Part):

Screenshot of CSS and Script References for FullCalendar
Load the CSS and JavaScript references on the page. This can be done in a Content Editor Web Part, but I prefer to add them in the PlaceHolderMain section.

Setting Up the Data View Web Part

To make this happen, I used a Data View Web Part (DVWP) to output the necessary JavaScript for the plugin to generate the calendar. I selected the web part zone and inserted a new DVWP. I chose the Calendar list as my data source, selected the Title field and inserted it as a “Multiple Item View.”

Screenshot of Calendar Data Source Displayed as a Multiple Item View
Insert a DVWP with the calendar as the data source, and insert the Title field as a "Multiple Item View."

I didn’t want to bog down the browser by loading hundreds of really old events, so I set a filter on the DVWP so that only events with a start time greater than or equal to today minus 90 days would be displayed (see this post for more information on setting up CAML query offsets). This allows people to view events up to three months in the past, as well as current and future events. I also sorted the events by start time in ascending order.


Use TinyMCE as the Rich Text Editor in SharePoint Forms

The default rich text editor (RTE) in SharePoint® 2007 doesn’t quite cut it in my opinion, and here’s why:

  • It’s based on an ActiveX control, so it only works in Internet Explorer. This alone is reason enough to replace it.
  • When creating a multiple line of text column in a custom list, you can only choose between “Plain text,” “Rich text,” or “Enhanced rich text” as the format for the column—not a lot of options. What if you want your users to have access to headings or other HTML elements?
  • It generates horrible, deprecated code:
    <DIV>Look at how <EM>bad </EM>this HTML is! If I start <SPAN style="color: #ff6600;">coloring things </SPAN>it gets really messy. I try to make sure I'm not getting too crazy with the content, but many users will select <SPAN style="font-family: 'Comic Sans MS';">their own fonts</SPAN>, <SPAN style="font-size: small;">sizes</SPAN>, <SPAN style="background-color: #33cccc;">colors</SPAN>, etc. instead of keeping things simple, which makes the markup even worse.</DIV>
    <DIV>Why does it use &lt;div&gt; tags instead of &lt;p&gt; tags? Why are the elements in all caps?</DIV>
    <DIV><SPAN style="color: #ff6600; font-family: 'Times New Roman'; font-size: medium;"><STRONG>Now if I try to make an entire section formatting differently, it gets weird with &lt;font&gt; tags and &lt;span&gt; tags.</STRONG></SPAN></DIV>
    <DIV><SPAN style="color: #000000; font-size: xx-small;">&nbsp;</SPAN></DIV>
    <DIV><SPAN style="font-size: xx-small;">Users probably don't know about the Clear Format button, so when they want to add "normal" text after their crazy colored, centered, bolded text, they try to match the normal text with even MORE direct formatting.</SPAN></DIV>
    <DIV><SPAN style="font-size: xx-small;">&nbsp;</SPAN></DIV>
    <DIV><SPAN style="font-size: xx-small;">Now try using this content in a branded site and see if your CSS holds up. Let a user edit this a few times and you'll have nested &lt;span&gt;s all over the place with all kinds of formatting.</SPAN></DIV>
  • Even the Full HTML RTE that you get on Publishing Pages (or if you create your own site column of this type) generates the same kind of markup. You have a few more options, like selecting basic HTML elements (paragraphs, headings, address, etc.), but you still can’t customize what appears.

A decade ago this RTE would have been really cool, but in today’s standards-compliant, feature-rich web, it just doesn’t hold up.

Enter TinyMCE, an open-source RTE with tons of customization OOTB, and even more thanks to numerous plugins (you can even write your own plugins if you need something that it doesn’t have). In this post I’ll show you how I replaced the SharePoint RTE with TinyMCE on my custom list forms using a little jQuery.

Note: This isn’t a tutorial about using TinyMCE for all rich text editing in SharePoint; it shows you how to use it on a per-form basis. (more…)

My First Printed Article: Best Practices for SharePoint Groups

I had my first printed article published in SharePoint Magazine’s latest issue! The article is called “Best Practices for SharePoint Groups.” I submitted the article as part of an Aspiring Authors competition. If you’re so inclined, take a moment to “Like” the article and help me out! Update 2013-09-17: is no longer available, but you […]

SharePoint Contextual Search – Updated

In a recent project created a page that features several Data View Web Parts pulling information from multiple lists within the site to create a dashboard-like experience. The stakeholders also wanted to be able to quickly search within each list, so I decided to include a custom search box at the top of each data view web part.

At first I thought I could use my custom search box that I wrote about in a previous post. The problem with that solution is that the JavaScript I created only works for a single search box because the ID is hard-coded into the functions. Therefore I modified the function to accept an ID attribute so it would accommodate multiple search boxes on the same page.

Updated Script and HTML

Here is the updated script:

// Search for the terms when the Search button is clicked

function customSearch(inputId,type,site,scope) {

	var searchUrl = site + "/_layouts/OSSSearchResults.aspx?" // Or "/_layouts/SearchResults.aspx?" if WSS 2003 or SP2010 Foundation
	var searchTerm = "&k=" + document.getElementById(inputId).value;
	var listParams = "&cs=This%20" + type + "&u=" + scope;
	window.location.href = searchUrl + searchTerm + listParams;

// Initiate the customSearch function when the Enter key is pressed

function searchKeyPress(buttonId,e) {
	// look for window.event in case event isn't passed in
	if (window.event) {
		e = window.event;
	if (e.keyCode == 13) {


Using a Current Date Offset in a CAML Query to Filter List Items and Other Useful CAML Resources

Recently I needed to create a Data View Web Part in MOSS 2007 that displayed all upcoming events, as well as all events that took place within the last week. The out of the box filtering options in SharePoint Designer (SPD) let you filter a Date and Time column by the “[Current Date]” or by a specific date. Unfortunately the UI does not let you specify an offset for the “[Current Date]” filter, but I found a few resources that showed me how to modify the CAML query that creates the filter to accomplish a date offset.

Setting Up the Filter

I set up my filter (Common Data View Tasks > Filter) to show all items whose Start Time (aka @EventDate) is greater than or equal to “[Current Date]” to build the initial CAML query.

[Current Date] filter
Set the DVWP to filter items based on the current date.
Next I switched to split view and found the CAML query in the code. It’s located in the <SharePoint:SPDataSource> tag (in the <DataSources> section):

	<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Geq&gt;&lt;FieldRef Name=&quot;EventDate&quot;/&gt;&lt;Value Type=&quot;DateTime&quot;&gt;&lt;Today/&gt;&lt;/Value&gt;&lt;/Geq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="true" ID="dataformwebpart2">
	<SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="537F0267-8B1E-47CD-8FC7-356D4949F604"/></SelectParameters>
	<UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="537F0267-8B1E-47CD-8FC7-356D4949F604"/></UpdateParameters>
	<InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="537F0267-8B1E-47CD-8FC7-356D4949F604"/></InsertParameters>
	<DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="537F0267-8B1E-47CD-8FC7-356D4949F604"/></DeleteParameters>


Create an Organization Chart in MOSS 2007 Using a Contacts List

Org Chart Chrome

Note: This article was originally posted on, but some of the code snippets were unescaped when it was published, so I decided to post it on my own blog with the correct code snippets.

I was recently tasked with finding a way to maintain an org chart for my department. If this were a single-use resource that didn’t need to be updated frequently, I would have chosen to create it in a program such as Visio or Adobe Illustrator (even PowerPoint would work well with its SmartArt capabilities). However, this is something we want to be as maintenance-free as possible so we aren’t rebuilding it as people come and go.

The department’s operations team already maintains a list of everyone in the department by using a SharePoint Contacts list, so we can pull data from that and build the org chart dynamically. This method does not require any custom code or web parts, so there’s no need to deploy anything on the server!

Sample Org Chart
This is the org chart that will be generated.


Load SharePoint Web-optimized Images into a DVWP

It finally happened. I’m starting a SharePoint category on my blog.

So, I recently worked on a project in which users were encouraged to upload photos that they took at volunteer events around the country. The stakeholder wanted to have a slideshow of these images on the event home page, and of course it had to look good.

I immediately thought of using a Data View Web Part and some jQuery because I knew I could create a nice-looking slideshow using one of the many jQuery plugins available on the web. However, I wanted to make sure the images looked good and fit within the slide show’s boundaries.

Luckily for me SharePoint creates web-optimized and thumbnail versions of images when they are uploaded into a Picture Library (not to be confused with the standard “Images” document library that is created for a site with the Publishing feature enabled). The tricky part was getting those optimized versions to load on the page instead of the original images, some of which were small, and some of which were many megapixels in size. Fortunately most of the leg work for this project was already done thanks to this post on the blog.