What is a query string?

In public opinion a query string is defined as “the part of a Uniform Resource Locator (URL) that contains data to be passed to web applications such as CGI programs.” [1] On SharePoint the start of the query string in the URL is indicated with a “?” and is always located at the end of the URL that locates the page.  A query string closely resembles that which is described in computer science as an Associative Array[2] that consists of a collection of (parameter, value) pairs.

SharePoint URL – Example

To understand better, all the information in the box below is regarded as the URL.  In turn a URL consists of a protocol (http), the location of the file to be displayed and then the start of the query string is indicated with a question mark “?”.  The URL is marked in blue and the query string is marked in the part that has both red and grey words.

Structure of a query string


Parameter Value
List = %7BCE37DB2D%2D5155%2D4887%2DA926%2D2DA4C09A4A96%7D &
RootFolder = %2Ftoday%2Fggatg%2FLibrary &
ContentTypeId = 0x01010000B660CFD6E4734DA2273F3C3320732304009B6443E42003BD4DB50DEED14366555C &
Source = https%3A%2F%2Fmyggatg%2FLists%2FMyWork/Today%2520News.aspx &
Mode = Upload &
CheckInComment = Comment  

*Note:  URL has no breaks; parameters were separated for easier reading!

The part of the URL after the file name and the question mark is regarded as the query string and is used to transfer values to variables for that specific page that loaded.  A query string can consist of pretty much anything but the main structure looks like this.

Symbol Usage Example
? Indicates that the rest of the URL is should be processed as the query string. http://mydomain.com/page.aspx?HorseLegs=4
= Binds the value to the parameter. HorseHead=1
& Separates each parameter, value pair ?HorseLegs=4&HorseEyes=2

What is a…

Variable Without going into programming too much – a value cannot be transferred from one area to another without storing within a container or better known as a variable.  Therefore a variable is placed instead of the actual value so that when the value changes it makes no difference the code.
Operator Operators are used to instruct or process and can be symbols (*/-) or words[3], luckily for this blog we’re only interested in the equals “=” operator.  The equal sign indicates that a value (“Horse”) is allocated to and represented by this variable (“mode”) e.g. Mode=Upload.

Customizing a query string

Users, Power Users and Designers don’t always use code to enhance the dynamics of pages on SharePoint and is regarded as an advantage.  When developer build dynamic pages, they often use code to generate the Query String part of a URL, unfortunately any other person who’s not dabbling in Visual Studio have to revert other means.  A query string consists of different parameters for a view/page displayed in SharePoint, for instance –

SharePoint Page Relative URL &Parameter=Value
Library View item ./[Name Of Library]/forms/DispForm.aspx ID; RootFolder; ContentTypeId; Source
Library Edit item ./[Name Of Library]/forms/EditForm.aspx ID; RootFolder; ContentTypeId; Source
Library New item ./_layouts/Upload.aspx List; RootFolder; ContentTypeId; Source; Mode; CheckInComment
List View item ./lists/[NameOfList]/DispForm.aspx ID; ContentTypeId; Source
List Edit item ./lists/[NameOfList]/EditForm.aspx ID; ContentTypeId; Source
List New item ./lists/[NameOfList]/NewForm.aspx Source; RootFolder

Parameter value examples

Parameter Value Description
ID 55 A numeric value
ContentTypeId 0x01010000B640CFF6E4794DA2273F3C3380732304009B6443E42003BD4DB50DEED14366555 A GUID uniquely identifying each content type.  Content types differ between lists and libraries.  Even though both a list and a library has a content type.
Source https%3A%2F%2Fmysub%2Edomain%2Eco The URL of the page to be returned to after saving or cancelling.  This URL is always encoded in hexadecimal and often has a query string of its own.
RootFolder %2Fmycollection%2FLibrary The path to the library/list converted to hexadecimal.  Used when uploading a document to a library but also appears as parameter when creating an item on a list, but has no value (go figure).
List {ca3e861f-98fd-402f-8d97-f2f3f38c0481} Used when a new library item is created (document uploaded).  Notice that the relative path (look at the above table) for creating a new item on a library changes to ./_layouts/Upload.aspx therefore the List parameter is added to identify which list to upload to.
Mode Upload Shows a Upload Successful message
CheckInComment Any%20comment%20here A string that contains the comment or an empty string if there is no check-in comment.[4] Spaces in the comment must be converted to hexadecimal.
InitialTabId and VisibilityContext InitialTabId=Ribbon.Browse&VisibilityContext=WSSTabPersistence Used as part of the Source parameter but can be used on any page.  The InitialTabId parameter indicates which part of the ribbon is active when landing on the page e.g if the page is in a document Library then the parameter’s value is “Library” (without the quotes).   When a custom ribbon is created, this is used have it show that ribbon by default.

Do’s and Don’ts in a query string

  • In the query string special characters must be converted to hexadecimal values preceded with a % i.e. %20 represents a SPACE or BLANK.
  • Because an ampersand is used to separate parameter, value pairs – whenever an ampersand appears within a value it is treated as a special character and must be converted to a hex value.
  • All pages that shows the properties of an item whether in a document library or a list must always have a ID parameter, value pair.

Converting to hexadecimal

To make life easier in converting a URL or the value for a parameter to hexadecimal, download the below Microsoft Excel Spreadsheet.  Thereafter, replace the URL  with any URL that you want to convert to hexadecimal (or paste anything); thereafter copy the converted value from cell.  Note that it will only convert special characters

Download the LinkProcessor to convert

Popup (Modal Dialogue) Hide MasterPage

Using IsDlg=1 as a parameter tells SharePoint that the page is being loaded within a dialogue, which means that it makes some changes to scrolling and the visibility of the Master Page.  Here is some more information (Thank you David Lozzi) –

We all know what IsDlg does… wait, what the…??

Note that this functionality works better when pages aren’t customised, specially on Publishing Architecture.

ShareTipOn – Sharing those things that can make life easier.