Useful SharePoint dlls

SharePoint has some great features like exporting list views to Excel or connecting Calendar events to your Outlook calendar. However, this might not always be easy for end users or users might not be willing to use the Ribbon menu to access these features (as in my case). Thankfully using REST, a little JavaScript can put this functionality directly onto a regular page as links to export to Excel or add an event to your Outlook calendar.

Exporting to Excel
In my first example, we had users who were rolling up list data onto a reporting page. From this page they wanted to export a different view of the list that we had set up for them. That, however, required them to navigate to the list and use the export to Excel button in the Ribbon menu:


On the reporting page, I added an Excel button with with a class Caption. With a line of JavaScript this can be set to the correct url:

var href = “http:// [sharepoint] / [site] /_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=[List Guid]&View=[View Guid]&CacheControl=1”
$(“.Caption a”).prop(“href”, href);

This will give you a button to export whatever view of the list you would like to Excel:


As much as, I’d like to take credit for this discovery, check this link below for the thread and this link to another blog with that solution.

Add to Outlook Calendar
In my second example. we created a SharePoint calendar for users to manage events. A workflow sends them an email with the link to the event when they change the category of an event indicating that this is an event they will be attending.

Like the first example. this is also pretty simple. We created a calculated column with the value of the link below:
http:// [sharepoint] / [site] / [list] /_vti_bin/owssvr.dll?CS=109&Cmd=Display&List=[List Guid]&CacheControl=1&ID=&Using=event.ics

Notice the event.ics at the end which give us an ics file to create an Outlook calender event. This can then be included in the workflow email and will give them a link like the below:

jQuery UI YouTube videos

We had a request to support videos on our public website. What they wanted was a list of videos (buttons, a title and description) and to have the video open in a modal pop up to play, graying out the background and focusing on the video. Easy enough.

With some simple jQuery and HTML this works pretty well. It does require both jQuery and jQuery UI.



The above uses a table to layout each video and its description and image in a row. This creates an image (play button), the iframe with the YouTube video, and the description of the video.

The important elements in the HTML above are the class name “videoRow” of the tr, the first td with the class “videoButton” which contains an a tag with the class “pre’ and a div with the class “video” that contains the iframe and YouTube video. The second td with the class “description” contains the text description.



The jQuery is pretty simple too.


For each a tag with class ‘pre’, the image becomes a UI button.


When a button is clicked, we first need to prevent the default behavior of a link click. If you look in the html above, href=”#” which could change the focus and scroll to the top of the page when clicked. e.preventDefault() will prevent this.

Secondly, we capture the button the video was attached to as a variable called buttonToAppendTo, this will be important later. The second variable is called videoToAttach and is a clone of the video element next to the button .


Still within the click function, we can then use the UI modal dialog to create a pop up window. The height and width are set to the height and width of the iframe and we set it to open at the center of the screen and create a lightbox effect.

On open a function is called that sets the css property of the video overflow to hidden. On close, the variables from before are used. If the modal dialog is closed, the video is still on the page and may still be playing. To avoid this it can be removed completly which will get rid of the element and stop it from playing. videoToAttach is the cloned video and can be inserted after the buttonToAppendTo. This will close out the video, stop it from playing, and allow the same button to be clicked and open the video again.

Add new Item prompt in SharePoint List

In a SharePoint list after clicking on the “Add new item” button, users will be taken to a form, fill out information and click save. At this point the form closes and the user can see the new item in their list. But what about when users want to add several items at once without clicking “Add new item” each time?

Luckily, there is the PreSaveAction() function that can be used to perform certain actions before the item is saved to the list:


Thanks to a little hunting and this stack overflow post, I was able to learn that PreSaveAction() allows the user to override the default save button click behavior. In my example, I wanted to prompt the user to create another item or close the form. This can be accomplished with a simple javascript alert, as seen above in my defined PreSaveAction() function. What I’m doing is getting the current form url and saving it to a variable called current URL.

First, CurrentURL will look something like this: http:// [SharePoint ]/ [site] / [list] /newForm.aspx.

Secondly, I am saving the source parameter (where I want to redirect to — this form to add another item), in a variable called redirect. redirect will look something like this: ?Source=http://[SharePoint]/[site]/[list]/newForm.aspx. Keep in mind that appending the ?Source parameter to a SharePoint URL will control where the user is redirect after saving an item. In my case I can redirect them back to the newForm after saving an item.

Third, on the save button click, I call my PreSaveAction() function, which prompts the user to create another item, if they say no, the item is saved and the window is closed. If they say yes, is set to the redirect variable. returns the querystring which is exactly the part I want to set. This will then save the item and then redirect the user to the newForm where they can submit another item.

Format Date

One of the things I find myself looking up frequently is Date Values for SharePoint. When creating custom display forms, you typically end up with date and time values that look something like this: 2013-07-24T21:00:00Z. This isn’t really a useful value (to an end user). To change it to something more readable open designer and the disp form:

Find the date field:

My Start Time field looks like this in the form:
The corresponding code in designer:
The xsl:value of tag contains the information to modify. The select attribute is equal to the EventDate value, which is the Start Time. To make a more readable value, it can be changed to:
The ddwrt namespace must be included to use a function like FormatDate. FormatDate, like the name implies, will change the formatting shown above to something useful or readable to an end user. Explanation of the parameters taken from the msdn page:
“The parameter szDate is converted to a DateTime. Based on the formatFlag parameter, which can have a value 0–15, a new DateTime string is constructed in the given locale lcid. Table 5 shows the results returned from this function.”
The above code will result in the below; a nicely formatted date for end users:
Check the msdn article for a list of formats.

Workflows still won’t publish

I’ve made two posts about this in the past: one about running previous versions of workflows and another about workflows not publishing.

In the first post, I discovered that when running workflows in the 2010 platform previous versions may need to be deleted; in the second, I found that the activity cache on your local machine can prevent new versions of your workflow from being published.

This post is related. If a workflow fails to run with the error: something went wrong to try again reload the page and the start the workflow, you may need to restart two services. To do so check the server SharePoint is on and look for the two services:

  • Service Bus Gateway
  • Service Bus Manager Broker

If either of these services is stopped, restart them and try to rerun your workflow.

Workflows won’t publish

So this can be incredibly frustrating. You update a workflow, save it without errors and then publish, but the next time the workflow runs your changes aren’t there and it’s running an older version. I have a post about dealing with an issue like this, but after following my own advice and clearing out the previous versions, I still had the same problem . I stumbled upon this blog post that explains the problem. There is a SPD activity cache for your local machine and clearing that out will solve the problem.

The path for me on 64 bit Windows 7 looks like this: %System Drive%\Users\%user name%\AppData\Local\Microsoft\WebsiteCache. Inside that directory there was a folder for each SharePoint site I have worked on and occasionally an identically folder with “01” or “02” after the name. All of these directories can be deleted. Make sure you have closed SPD designer before deleting the directories, then reopen designer and publish a workflow.

Multiple check boxes default values

I recently had a requirement to have a choice column with check boxes and have all options selected by default. After a little hunting I came across the syntax which is rather easy:


In the default value box, select Calculated Value and enter the above.

This leads to check boxes being selected on item created.

Better ULS Logging in PowerShell

Stumbled upon this post when trying to use the ULS logger to see an error:

See the blog above for full details but here is a simplified way to get an error:

1. Get correlation id from window

2. in PowerShell (run the following commands):

Merge-SPLogFile -Path “.\error[x].log” -Correlation “85ea729c-071c-d0b1-d6c7-065c6284a50f”

Dir *.log

I name my log errorx where x is a number and delete them after I I’m done.

Saves to C:\Users\ [your user name]

3. Open ULS Viewer > Open File and select error[x].log

Way easier than hunting through ULS logs.

Content Query ‘No results” message

By default Content Query Web Parts (CQWP) don’t display any text on a page when no results are returned. The message is only displayed in “edit mode” when a content manager or developer is editing the page. This can be frustrating because you might want to display a message that says that nothing has been returned. In my case we wanted to query a calendar for upcoming events that meet some conditions and a message if there wasn’t any. The solution is simple:

1. Open Designer and your root site collection (http:// [site collection name])

2. Select All Files > Style Library > XSL Style Sheets

3. Open ContentQueryMain.xsl  (good idea to make a copy called custom)

4. Look for the item template OuterTemplate.Empty:


Note the xsl:if tag that indicates that the message will only be shown when in edit mode. Add a custom message above.

Running previous versions of workflows

Recently, we upgraded to SharePoint 2013 from SharePoint 2010 and one of the strangest things that happened in the transition was several workflows were running incorrectly. Simple solution: recreate them.

contribute_feedbackThankfully none were too complex and were recreated quickly. Our most important workflow is arguably a feedback workflow that allows users to click on a “Contribute Feedback” link at the bottom of every page. There are two workflows attached to this list: Feedback and FeedbackClosed. Feedback runs on Item Created and captures the user who created the item, the page they are on (which the feedback applies to), the message in the feedback, the category (typo, missing information,  incorrect information, etc.) and the urgency (Low, High). This workflow sends an email to our dev team with links to the page the feedback applies to and the feedback record.

Feedback also contains a status field and the dev team can change this to completed which triggers the FeedbackClosed workflow and sends a response to everyone on the dev team and the user who created the item with a message of the resolution.

The issue was during recreating the Feedback workflow I misspelled Feedbacik, so I ran the workflow and then saw this in the email:  misspelling. So I opened the workflow in SharePoint Designer and corrected it. I saved and published and created a test workflow to see the same problem: misspelling.  After a few hours of trying to figure this I realized the mistake I made. I navigated to the Feedback list and selected Workflow settings to see about twenty previous versions on this page as well as my Feedback current version that I wanted to run. I selected “Remove” for all previous version and “Allow” for the current version. This ran the correct version.

TL;DR: If previous version of workflows are running navigate to the list > Workflow settings and remove all previous versions.