Detect if New Folders are allowed in SharePoint List/Library using Lists web service from remote application (works across SharePoint 2007, 2010, 2013)

Today I found myself tasked with finding a common method for detecting if a SharePoint list/library had been configured to allow new folders from a remote client application. The method also had to work across all versions of SharePoint (well at least 2007, 2010, 2013 on-premise and in the cloud). This ruled out using client side object model so my investigation turned to web services (yes they are deprecated in SP2013 so be careful using them going forward).

The Lists web service provides a few different ways to return the XML schema of a list(s) (e.g. GetList or GetListCollection)

Here’s a snippet of what the XML looks like that you get back from these web service methods.

<List DocTemplateUrl="" DefaultViewUrl="/Lists/announce123/AllItems.aspx" MobileDefaultViewUrl="" ID="{F194025B-A0F2-4318-950A-9197AD8D2285}" Title="announce123" Description="" ImageUrl="/_layouts/15/images/itann.png?rev=23" Name="{F194025B-A0F2-4318-950A-9197AD8D2285}" BaseType="0" FeatureId="00bfea71-d1ce-42de-9c63-a44004ce0104" ServerTemplate="104" Created="20130510 01:18:39" Modified="20131015 03:57:05" LastDeleted="20130802 04:12:40" Version="3" Direction="none" ThumbnailSize="" WebImageWidth="" WebImageHeight="" Flags="603983880" ItemCount="6" AnonymousPermMask="0" RootFolder="" ReadSecurity="1" WriteSecurity="1" Author="9" EventSinkAssembly="" EventSinkClass="" EventSinkData="" EmailAlias="" WebFullUrl="/" WebId="8f69cd67-4cc9-42f4-b104-2fe1e2b7944e" SendToLocation="" ScopeId="fadcba6a-3b00-44b9-a813-db5dc5cf3858" MajorVersionLimit="0" MajorWithMinorVersionsLimit="0" WorkFlowId="" HasUniqueScopes="False" NoThrottleListOperations="False" HasRelatedLists="" Followable="False" AllowDeletion="True" AllowMultiResponses="False" EnableAttachments="True" EnableModeration="False" EnableVersioning="False" HasExternalDataSource="False" Hidden="False" MultipleDataList="False" Ordered="False" ShowUser="True" EnablePeopleSelector="False" EnableResourceSelector="False" EnableMinorVersion="False" RequireCheckout="False" ThrottleListOperations="False" ExcludeFromOfflineClient="False" CanOpenFileAsync="True" EnableFolderCreation="False" IrmEnabled="False" IsApplicationList="False" PreserveEmptyValues="False" StrictTypeCoercion="False" EnforceDataValidation="False" MaxItemsPerThrottledOperation="5000" xmlns="<a href=";">"</a> />

After diligently looking through all of the attributes here it doesn’t seem like the “New Folders allowed” option is included. One attribute did catch my eye however… the “Flags” attribute. What was this for and could it hold the secret I was after?

I went into SharePoint toggled the Allow New Folders setting reran my code to call the Lists web service and grabbed the XML again to test if anything changed in the Flags attribute.

On my initial run through the Flags attribute had a value of “603983880” (no new folders allowed), on my second run through the Flags attribute had indeed changed to “67112968” (new folders allowed). Great, somehow this Flags attribute holds the key, but how do you make use of this?

My understanding of flags is that they work on an individual bit level, essentially every bit can have an on/off state. So this means a flag can hold the state of many different variables. So time to get binary! It’s been a few years since I last sat in a classroom and figured out binary/decimal conversions with a pencil and paper so let’s just cheat – or actually let’s use a much faster tool for the job.

I started up Windows Calc and put it into Programmer mode.


Next set the calc to Dec(imal) mode and cut/paste the initial value of the flag in


Now click on Bin(ary) to convert the number and we get:


This on it’s own gives us nothing, but if we repeat the steps with the second value of the flag (after we toggled the allow New Folders setting) we get the binary value:


Now we have something to work with, if you align these 2 values under each other you can see that just a single bit has changed.


That’s the bit that represents the “Allow New Folder” setting.

Before we dive into the code for the solution I’ll explain why the values you see in the code don’t look like the binary numbers above. Binary is damn hard to read, very long to type, and prone to typing errors. I’ve converted these binary numbers to Hex in order to do the comparisons. When you convert these 2 numbers to Hex (using calc again) you get


As you can see, we still have our difference of a single number in the sequence but it’s a lot less digits.

So now all that’s left is the code that checks if this bit has been set or not.

// Detect if folders are allowed in this list/library - it's hidden in the Flags attribute.
UInt64 flags = 0;
bool foldersAllowed = false;
string flagsStr = listNode.Attributes.GetNamedItem("Flags").InnerText;
if (UInt64.TryParse(flagsStr, out flags))
    foldersAllowed = ((flags & ((ulong)0x20000000L)) == 0L);

About Cameron Dwyer

Architect and developer at OnePlace Solutions. Passionate about delivering compelling solutions on the Office 365/SharePoint platform. Addicted to coffee.

Posted on November 13, 2013, in C#, SharePoint and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: