Beispiel #1
0
        public static void UpdateWithAction(this SPContentType contentType, Action <SPContentType> action, bool updateChildren = false, bool throwOnSealedOrReadOnly = false)
        {
            if (action == null)
            {
                return;
            }

            if (contentType.ParentList == null)
            {
                updateChildren = false;
            }

            action(contentType);
            contentType.Update(updateChildren, throwOnSealedOrReadOnly);

            if (contentType.ParentList != null)
            {
                return;
            }

            Dictionary <string, List <string> > listUrls = SPHelper.GetListUrls(contentType);

            foreach (string webUrl in listUrls.Keys)
            {
                using (SPWeb web = contentType.ParentWeb.Site.OpenWeb(webUrl))
                {
                    using (new Unsafe(web))
                    {
                        foreach (string listUrl in listUrls[webUrl])
                        {
                            SPList list = web.GetListByUrl(listUrl);

                            SPContentType ct = list.GetContentTypeById(contentType.Id);

                            if (ct != null)
                            {
                                action(ct);
                                ct.Update(throwOnSealedOrReadOnly);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static bool ContainsContentTypeWithId(this SPList list, SPContentTypeId id)
        {
            SPContentType ct = list.GetContentTypeById(id);

            return(ct != null);
        }