Monday 17 October 2011

Programmatically check if Allow management of content types is enabled on a List in SharePoint 2010


To Programmatically check if Allow management of content types is enabled on a List in SharePoint 2010 we can either use the Object model or the GetList webservice.

Object Model -

SpList list = web.Lists['mylist'];
if(list.ContentTypesEnabled)
{
//Its enabled
}

Using WebServices -
public static bool GetAllowContentTypes(string listName)
{

listservice.Lists ls = new listservice.Lists();
ls.Url = "http://SpSite/_vti_bin/lists.asmx";
ls.UseDefaultCredentials = true;
UInt64 flags = 0;
bool contentTypesAllowed = false;

XmlNode node = ls.GetList(listName);

XElement element = XElement.Parse(node.OuterXml);

var result = from e in element.Attributes("Flags")
select e.Value;

if (result != null && UInt64.TryParse(result.First().ToString(), out flags))
contentTypesAllowed = ((flags & ((ulong)0x400000L)) != 0L);
else
return false;

return contentTypesAllowed;
}

Ads by Google

No comments:

Post a Comment