Tuesday, December 3, 2013

Check if ContentType Already Exists in SharePoint Site

public bool CheckContentType(string spsite, string contenttypename)
        {
            bool ContentTypeFound = false;
            try
            {
               
                SPSite a = new SPSite(spsite);
                SPWeb web = a.OpenWeb();
                SPContentType myContentType = web.ContentTypes[contenttypename];
                if (myContentType != null)
                {
                    //found
                    ContentTypeFound = true;
                }
                else
                {
                    //Not found
                    ContentTypeFound = false;
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
           
            return ContentTypeFound;
        }

No comments:

Post a Comment