Calculated Columns for Cascading Drop-Downs in SharePoint Lists and Libraries

SharePoint list or library users need a simple way to enter data in one column that depends on what was entered in another, but out-of-the-box SharePoint 2007 or 2010 does not support direct cascading functionality. Using jQuery for SharePoint Web Services might be an option for cascading drop-downs, but you are not allowed to use SharePoint Designer to modify the EditForm, and besides, you want the behavior to work inside the list/library itself in datasheet view and not just in the EditForm. Lookup columns could do the trick, but let’s say you’re already at the farm-wide threshold setting of eight per list/library. Managed Metadata in the Term Store perhaps? But, the terms are not universal and getting a few simple entries requires more than a few clicks.

If there are only a few fields that relate to one another, one straightforward option might be to create a Choice column that allows users to select a delimited text string that contains all of the relationships in a single line, and then use Calculated Columns to parse the string out into separate columns.

For example, a Choice column called “Section – Category” could delimit a drop-down menu of sections and categories with a semi-colon character, making it pretty easy for people to spot the combo they’re looking for:

1 – Pre-Visit; 1 – Charting
1 – Pre-Visit; 2 – Phone Calls / Messaging
1 – Pre-Visit; 3 – Registration
1 – Pre-Visit; 4 – Scheduling
2 – Patient Visit; 5 – Check-in
2 – Patient Visit; 6 – Chronic Care / Education
2 – Patient Visit; 7 – MyChart
2 – Patient Visit; 8 – Orders / Charting
2 – Patient Visit; 9 – Rooming
3 – Post-Visit; 10 – Charting
3 – Post-Visit; 11 – Orders
3 – Post-Visit; 12 – Phone Calls / Messaging
4 – Bars; 13 – Between Visits
4 – Bars; 14 – Daily Work & General

One calculated column called “Section” and another called “Category” could contain formulas that split the string into left and right contents. But let’s take it up a notch and turn the string into four columns – “SectionID”, SectionTitle”, CategoryID”, and “CategoryTitle.” See where this is going?

SectionID – the formula is pretty basic, but it’s not just getting the first character from the left in the string, because the number might end up with more than one character. It’s about getting everything to the left of the first space ” ” character. Now, note this dash has spaces around it. This is important visually for users, but it also serves to make it different than any hyphens used in the words. So, after finding the ” – ” character, the space needs to be subtracted with a “-1” thusly:

=LEFT([Section - Category],FIND(" ",[Section - Category])-1)

SectionTitle – here the formula starts getting a bit more complex. We want the words to the left of the “;” and to the right of the ” – “. Note the use of “-1” here too to remove spaces around the dash, and also note that there is a space on the right of the dash in “- “:

=RIGHT(LEFT([Section - Category],FIND(";",[Section - Category])-1),LEN(LEFT([Section - Category],FIND(";",[Section - Category])-1))-FIND("- ",LEFT([Section - Category],FIND(";",[Section - Category])-1))-1)

CategoryID – same fun, but now wanting all the numbers from the string on the right of the “;” that are left of the ” – ” on the right hand string:

=LEFT(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])-1),FIND(" -",RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])-1))-1)

CategoryTitle – not as simple as it looks, this task is to get all the words from the right side of the “;” and the right side of the ” – ” that’s in the right side string;

=RIGHT(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])),LEN(RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])))-FIND("- ",RIGHT([Section - Category],LEN([Section - Category])-FIND(";",[Section - Category])))-1)

Selecting a single item in the Choice column like “1 – Pre-Visit; 1 – Charting” yields:

SectionId SectionTitle CategoryId CategoryTitle
1 Pre-Visit 1 Charting

This method of creating cascading drop-down columns can work well as long as the choices are simple – meaning limited to two to three columns. The formulas can get as complex as your brain can comprehend, and calculation speed does not seem to be an issue.

Generate a hierarchical XML file from SharePoint list

You need to get data from a SharePoint 2010 list and generate a hierarchical XML file that can be used as a data source for a Flash movie on a site. Your enterprise SharePoint Admins want their platform to stay as out of the box as possible, and they have good reasons to minimize server-side customizations and the use of SharePoint Designer.

Undaunted, you turn to the SharePoint Client Object Model for a console application that can be launched from a button on a page or by a workflow. In effect your app needs to perform the following automation tasks:

  • Get a flat XML file of the data
  • Convert the flat XML file into a hierarchical file
  • Save the file as an XML document and upload it to a SharePoint document library

Step 1 – Get data to a flat XML file
The first step is to get data from a SharePoint list and store it as XML in memory. This could be done in one of several ways: SPList class and a CAML SPList class and LINQ query, Web Services, GetListItems, or the URL protocol of the RPC method. This solution will use URL Protocol, because it’s a simple and transparent way to access the data. This step also needs to:

  • Get the XML output from a special View of the list rather than the default view of the list, so all of the columns can be shown all of the time without affecting data entry or management
  • Trim off any extraneous characters from the values that come from SharePoint lists, like dates, URLs, or strings delimited with “;#”
  • Resolve a potential SP2010 security exception when accessing from the localhost
  • Build a valid URL to the document, regardless of whether it is a PDF or a Web link
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
// used for uploading - clientcontext and memorystream
using Microsoft.SharePoint.Client;
using System.IO;

namespace PMGDialXML
    class Program
        static void Main(string[] args)
            // Use the URL protocol of the RPC method to get data from
            // the "XML Generator View" which displays all of the fields
            string sUrl = "http://rootweb/site/subsite/_vti_bin/owssvr.dll?Cmd=Display&List={E3DFD89F-4DA3-4418-8674-D692B59CCBC4}&View={4E44F267-C5F7-42B6-8871-0194604177EA}&XMLDATA=TRUE";

            // Resolve a potential SP2010 security exception when accessing from the localhost
	         XmlUrlResolver xmlResolver = new XmlUrlResolver();
	         xmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
	         XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
	         xmlReaderSettings.XmlResolver = xmlResolver;

            // Define LINQ Namespace objects (System.XML.Linq)
            XNamespace s = "uuid:BDC6E3FA-6DA3-11d1-A2A3-00AA00C14882";
            XNamespace dt = "uuid:C2F41030-65B3-11d1-A29F-00AA00C14882";
            XNamespace rs = "urn:schemas-microsoft-com:rowset";
            XNamespace z = "#RowsetSchema";

            // Get the list XML (System.XML)
            XDocument sUrlDoc = XDocument.Load(XmlReader.Create(sUrl, xmlReaderSettings));

            // Store fields returned from owssrv in a new XML variable
            var xVar =
                new XElement("vWorkflows",
                    sUrlDoc.Root.Descendants(z + "row").Select(r => new XElement("vSection",
                        new XAttribute("sectionTitle", TrimValue(r.Attribute("ows_SectionTitle").Value)),
                        new XAttribute("sectionId", TrimValue(r.Attribute("ows_SectionID").Value)),
                        new XAttribute("show", (r.Attribute("ows_ShowOrHide").Value)),
                        new XElement("vCategory",
                            new XAttribute("catTitle", TrimValue(r.Attribute("ows_CategoryTitle").Value)),
                            new XAttribute("catRef", TrimValue(r.Attribute("ows_CategoryID").Value)),
                            new XElement("vType",
                                new XAttribute("typeTitle", TrimValue(r.Attribute("ows_TypeTitle").Value)),
                                new XAttribute("typeRef", TrimValue(r.Attribute("ows_TypeID").Value)),
                                new XElement("vLink",
                                    new XAttribute("linkNum", ""),
                                    new XElement("linkTitle", TrimValue(r.Attribute("ows_Document").Value)),
                                    new XElement("linkUrl", WhatsUpDoc(TrimValue(r.Attribute("ows_Document_x003a_FileName").Value) + ";" + TrimValue(r.Attribute("ows_Dial_x0020_Title_x003a_DocumentU").Value))),
                                    new XElement("linkSummary", ""),
                                    new XElement("linkKeywords", ""),
                                    new XElement("pubDate", TrimDate(TrimValue(r.Attribute("ows_Document_x003a_PublishDate").Value))),
                                    new XElement("lastUpdate", TrimDate(TrimValue(r.Attribute("ows_Document_x003a_LastUpdated").Value)))

Step 2 – Construct hierarchical XML document
Read (aka query) the in-memory XML and reconstruct the a collection of elements and attributes into a hierarchical XML output using LINQ to XML. Note that the results of one LINQ query expression can be the input of another LINQ expression. Code it in a way that matched up with the XML output to make it easier for those that follow. And a few other things:

  • If item is set to “Show” in the list then show it, otherwise hide it.
  • Sort the output by SectionId rather than by SectionTitle to conform to the SWF design and match the existing XML exactly
           // Create new hierarchical XML document from the flat XML variable
            XDocument xDoc = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XComment("XML Source Data for Dial Flash"),
                new XElement("workflows",
                    from sec in xVar.Elements("vSection")
                    where (string)sec.Attribute("show").Value == "Show"
                    orderby (string)sec.Attribute("sectionId").Value ascending
                    group sec by new {
                        secT = (string)sec.Attribute("sectionTitle").Value,
                        secId = (string)sec.Attribute("sectionId").Value
                    } into gsec
                    select new XElement("section",
                        new XAttribute("sectionTitle", gsec.Key.secT),
                        new XAttribute("sectionId", gsec.Key.secId),
                        from cat in gsec.Elements("vCategory")
                        orderby (string)cat.Attribute("catTitle").Value ascending
                        group cat by new {
                            catT = (string)cat.Attribute("catTitle").Value,
                            catId = (string)cat.Attribute("catRef").Value
                        } into gcat
                        select new XElement("category",
                            new XAttribute("catTitle", gcat.Key.catT),
                            new XAttribute("catRef", gcat.Key.catId),
                            from typ in gcat.Elements("vType")
                            orderby (string)typ.Attribute("typeTitle").Value ascending
                            group typ by new {
                                typT = (string)typ.Attribute("typeTitle").Value,
                                typId = (string)typ.Attribute("typeRef").Value,
                            } into gtyp
                            select new XElement("type",
                                new XAttribute("typeTitle", gtyp.Key.typT),
                                new XAttribute("typeRef", gtyp.Key.typId),
                                from lnk in gtyp.Elements("vLink")
                                orderby (string)lnk.Attribute("linkNum").Value ascending
                                group lnk by new {
                                    linN = (string)lnk.Attribute("linkNum").Value,
                                    linT = (string)lnk.Element("linkTitle").Value,
                                    linU = (string)lnk.Element("linkUrl").Value,
                                    linS = (string)lnk.Element("linkSummary").Value,
                                    linK = (string)lnk.Element("linkKeywords").Value,
                                    pubD = (string)lnk.Element("pubDate").Value,
                                    lasU = (string)lnk.Element("lastUpdate").Value
                                } into glnk
                                select new XElement("link",
                                    new XAttribute("linkNum", glnk.Key.linN),
                                    new XElement("linkTitle", glnk.Key.linT),
                                    new XElement("linkUrl", glnk.Key.linU),
                                    new XElement("linkSummary", glnk.Key.linS),
                                    new XElement("linkKeywords", glnk.Key.linK),
                                    new XElement("pubDate", glnk.Key.pubD),
                                    new XElement("lastUpdate", glnk.Key.lasU)

Yep, there’s another way to do it that groups the top level, but we won’t do that here. It looks something like this …

	   // Alternate way to do it
	   var query = xVar.Elements("vSection").
	      OrderBy(grp => (string)grp.Attribute("sectionTitle").Value).
	      GroupBy(grp => (string)grp.Attribute("sectionTitle")).
	      Select(grp => new XElement("section", grp.First().Attributes(),
	            grp.Select(vsec => new XElement("category",

	   var xml = new XElement("workflows", query);

Step 3. Save XML document to document library
This is where the Client Object Model comes in. You’ll also use System.IO for memorystream.

            // Save XML Document to a string
            string upDoc = xDoc.ToString();

            // Upload XML Document to a SharePoint Document Library
            public static void UploadXmlFile(string xmlContent)
            // Define the site, library and file variables
            string webUrl = "",
                   siteUrl = "/site/subsite/subsubsite",
                   libraryName = "documents",
                   fileName = "swf_file.xml";

            // Instantiate the site
            ClientContext clientContext = new ClientContext(webUrl + siteUrl);

            // Process the XML file
            using (MemoryStream memoryStream = new MemoryStream())
                // Write the file XML contents into a MemoryStream object ...
                StreamWriter writer = new StreamWriter(memoryStream);
                memoryStream.Position = 0;

                // ... and save it in the Document Library (set to "true" to overwrite the file)
                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, siteUrl + "/" + libraryName + "/" + fileName, memoryStream, true);

This code feeds a Flash movie that allows users to dial in on documents by a predefined taxonomy on a SharePoint site. What once required hours of manual XML file edits and uploads can now be done in one click, and the door is now open to automating the entire document upload, approval and management process using workflows and InfoPath web forms. Presumably, this kind of approach can also be used with other kinds of animated web parts that use XML as a data source.

Reporting Services web parts on SharePoint page

Adding Report Builder web parts to SharePoint 2010 made the page colorful and intelligent, but the UI lacked a bit. The parts that took up little horizontal space and lots of vertical space looked kind of goofy;

  • the data abruptly cut off vertically after 11 inches
  • they required a fixed vertical setting at about 2000px
  • they would not flow horizontally with the page’s liquid layout
  • they sometimes created two layers of scroll bars making moving around on the page very awkward

Data typically cuts off vertically after a certain length because of paging; the page breaks based on the Interactive Size setting of the Report pane set in Report Builder. The fix is to set the InteractiveSize settings to 0. Might as well do it on both horizontal and vertical properties.

Avoid the fixed vertical and horizontal web part settings in SharePoint by using a wee bit of jQuery, unless you are free to do it with a server-side package. Start by removing any Height and Width settings in the web part.

Then add jQuery code in an HTM file strategically placed in a Documents Library like “Scripts” at some root site and call the file from a Content Editor web part on the report page. The following code seems to work – it works on ALL Report Builder web parts on the page and avoids conflicts with other parts.

<style type="text/css">
	.dynamic-height {height:auto !important;}
<script src="http://domainname/somerootsite/scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
	// use setTimeout method to delay
	$(window).load(function() {
<script type="text/javascript">
	function FixReport() { 
		// fix report height
		$('div[RSViewer="RSViewer"] div').addClass('dynamic-height');
		// remove report horizontal scrollbar
		$('div[id$="ReportViewer"]').css("overflow-x", "hidden");

Even if the Report Builder web parts only have 2″ to 5″ of width, you can extend the part up to 12″ wide. It will allow a single column page fill out nicely to the right when the browser expands to fit larger screens – same for parts in side-by-side zones.

See Article 1, Article 2, and Article 3

Using HTTP-EQUIV to refresh a page

Consider this scenario. A patient enters a tele-health kiosk, fills out an InfoPath survey and privacy agreement form and clicks a submit button. The form thanks the patient for filling out the info and alerts a nurse to start an interactive session. As the nurse and patient interact in their session, the form automatically brings up a new form in the browser window ready for the next patient.

There’s probably a better way to do it, but using HTTP-EQUIV in the tag is a simple way to automate that InfoPath thank and refresh process. For example, have the InfoPath form open to a ThankYou page that contains something like the following Meta tag which opens the form and uses &Source to refer back to itself:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
	    <meta HTTP-EQUIV="REFRESH" content="5; url=">
	    <title>HIPAA Acknowledgement and Authorization for Treatment Success</title>
		<style type="text/css">
			body {
			.thanks, .note {
				font-family:Arial, Helvetica, sans-serif;
			.thanks {
				margin-top: 300px;
				font-size: 24px;
			.note {
				font-size: 14px;
		<div class="thanks">Thank you.</div><br/>
		<div class="note">Your form has been sent, and the appointment will begin soon.</div>

See article and article

Automatically closing a SharePoint 2010 Edit form opened from a Reporting Services web part

SharePoint 2010 Edit and Display forms can be modified with InfoPath. This opportunity comes with a few new bugs, but the UI and functionality can be compelling.

It takes a snippet of Javascript, but a Reporting Services web part can open one of these new list or library Edit forms with a GoToURL action. On submit or close, however, the form will either close to the list it came from or it will close to a “This form has been closed” window. It matters not whether the form is opened in the same window (target = _self) or in a new window (target = _blank). Nor does it matter if the form is set to close on submit. Neither option closes the form back to the page that launched it, and both interrupt the user flow with additional clicks to close the form window.

If adding code to the form page is a non-starter, one workaround is to close the form to another page where script can be added. This is done using the &Source part of the URL string that opens the window.

Step 1 – Create a simple SharePoint ASPX page. This can be done using SharePoint Designer 2007 (adds the basic ASPX lingo automatically), Visual Studio, NotePad++, or etc. That should result in something like the following tags:

<%@ Page Language="C#" %>
<html dir="ltr">
	<head runat="server">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			<title>Untitled 1</title>
		<meta name="Microsoft Theme" content="Providence 1011, default">
		<form id="form1" runat="server"></form>

Step 2 – Add Javascript to the section that has the page close itself on open. Calling open() first, bypass a potential window close confirmation dialog box.

<script language="javascript" type="text/javascript">"", "_self");

Step 3 – Save the page as “Close.aspx” and upload it to a Document Library on the SharePoint site that is easy to access.

Step 4– Set the &Source parameter in the Report Builder web part’s URL expression to the url of the Close.aspx page. This is the URL that InfoPath will return the user to after the browser form is closed. The example below links to an Edit form in an External List that opens a specific item based on its BDCIdentity ID:

="javascript:void('http://sitecollection/site/Lists/ListName/Item/editifs.aspx?ID=" + Fields!BDCIdentityKey.Value + "&Source=http://sitecollection/site/Pages/Close.aspx','_blank'))"

The resulting link should open the Edit form in a new window, and when the form is saved or closed, it goes to the close.aspx page that closes instantly, leaving the user back at the window of origin.


  • Access Denied for Visitors on a SharePoint Page with Reporting Services Webpart

    If you are working in SharePoint 2010 and discover that users in the Visitors group or All Authenticated Users are unable to open pages that contain a Report Services web part with an Access Denied error…

    error message… you might think the issue is related to permissions. Then again, it may just be something quirky about the platform that prevents groups with Read permission from seeing reports that were published as a minor version.

    The solution: make sure the reports are published as a Major version. You can use “draft check” button on page tab of the ribbon bar to Publish a Major Version, or change the Report Library versioning settings to publish only major versions and re-save the reports.

    How to use a URL to launch Report Builder 3.0 and edit a report

    Make it easy for SharePoint site owners to edit their custom SSRS reports, by giving them a hyperlink that opens the Report Builder 3.0 application to a specific report.

    This MSDN article and this Technet article show how the Report Builder application can be opened from a browser.

    A native mode installation URL would be: 

    … where “8000” would be the port you used when setting up the ReportServer service, while SSRS configured in SharePoint integration mode would take the form of:

    You might find it easier to open the application to a specific report by appending a “?” to the end of the latter URL followed by the report path. Replace spaces in the path after the question mark with plus signs, and skip the “rdl” file extension on the end. For example, to access a “Department Report.rdl” file in a library on a SharePoint site called “Reports Library,” the following URL should work (all in one line):