public bool IsChildOf(object id)
        {
            if (id is string)
            {
                return(m_contentTypeId.IsChildOf(new SPContentTypeId(id as string)));
            }

            if (id is SPContentTypeIdInstance)
            {
                return(m_contentTypeId.IsChildOf((id as SPContentTypeIdInstance).m_contentTypeId));
            }

            return(false);
        }
        private static void UpdateListItemEventReceivers(SPSite site)
        {
            //Upgrade All Lists Instances with new Event Receiver Assembly for
            //Lists based on the Training Course Content Type

            string          newAssembly   = "Contoso.TrainingManagement, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5"; //our new assembly info
            string          newClass      = "Contoso.TrainingManagement.TrainingCourseItemEventReceiver";
            SPContentTypeId contentTypeId = new SPContentTypeId(ContentTypes.TrainingCourse);                                                //our custom ctype

            foreach (SPWeb web in site.AllWebs)
            {
                using ( web )
                {
                    for (int i = 0; i < web.Lists.Count; i++)
                    {
                        SPList          list      = web.Lists[i];
                        SPContentTypeId bestMatch = list.ContentTypes.BestMatch(contentTypeId);
                        if (bestMatch.IsChildOf(contentTypeId))
                        {
                            for (int j = 0; j < list.EventReceivers.Count; j++)
                            {
                                SPEventReceiverDefinition eventReceiverDefinition = list.EventReceivers[j];
                                if (String.Compare(eventReceiverDefinition.Assembly, newAssembly, true) != 0)
                                {
                                    list.EventReceivers.Add(eventReceiverDefinition.Type, newAssembly, newClass);
                                    eventReceiverDefinition.Delete();
                                    list.Update();
                                }
                            }
                        }
                    }
                }
            }
        }
        public override int IsMatch(Microsoft.SharePoint.SPList list, SPContentTypeId ctId, int ItemId)
        {
            if (string.IsNullOrEmpty(ContentTypeID))
            {
                return(SearchMatchLevel.NONE);
            }
            SPContentTypeId ct;

            try
            {
                ct = new SPContentTypeId(ContentTypeID);
                if (ct.CompareTo(ctId) == 0)
                {
                    return(SearchMatchLevel.ITEM_BY_CT_ID_EXACTLY);
                }
                if ((IncludingChilds) && (ct.IsChildOf(ctId) || (ct.CompareTo(ctId) == 0)))
                {
                    return(SearchMatchLevel.ITEM_BY_CT_ID_INHERITED);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace(ex, Logging.SeverityEnum.Error);
            }
            return(SearchMatchLevel.NONE);
        }
Example #4
0
 private static void RemoveCTDirectDescendantFromList(SPWeb web, SPList list, SPContentTypeId ctId)
 {
     SPContentTypeId bestMatch = list.ContentTypes.BestMatch(ctId);
     if (bestMatch.IsChildOf(ctId))
     {
         if (bestMatch.Parent.Equals(ctId))
         {
             // Is direct descendant
             list.ContentTypes.Delete(bestMatch);
         }
     }
 }
Example #5
0
        public static SPContentType GetContentTypeById(this SPList list, SPContentTypeId id)
        {
            SPContentType   ct      = null;
            SPContentTypeId matchId = list.ContentTypes.BestMatch(id);

            if (matchId.IsChildOf(id))
            {
                ct = list.ContentTypes[matchId];
            }

            return(ct);
        }
Example #6
0
 public static SPModelDescriptor Resolve(SPContentTypeId contentTypeId)
 {
     lock (syncLock) {
         foreach (KeyValuePair <SPContentTypeId, SPModelDescriptor> entry in ContentTypeDictionary)
         {
             if (contentTypeId.IsChildOf(entry.Key))
             {
                 return(entry.Value);
             }
         }
     }
     throw new ArgumentException("contentTypeId", String.Format("There is no type associated with content type ID '{0}'", contentTypeId));
 }
        private void RemoveCTDirectDescendantFromList(SPWeb web, string listUrl, SPContentTypeId ctId)
        {
            SPList list = web.GetList(GetListUrl(web.ServerRelativeUrl, listUrl));

            SPContentTypeId bestMatch = list.ContentTypes.BestMatch(ctId);

            if (bestMatch.IsChildOf(ctId))
            {
                if (bestMatch.Parent.Equals(ctId))
                {
                    // Is direct descendant
                    list.ContentTypes.Delete(bestMatch);
                }
            }
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;

            SPList resourceList = web.Lists[Utilities.GetResourceListName(web)];

            resourceList.Hidden = true;
            resourceList.ContentTypesEnabled = true;

            // Set up content types
            SPContentTypeId scriptWebCTID   = new SPContentTypeId("0x01005288A3160BABA04DAA0B8A015A3D490101");
            SPContentTypeId bestMatchScript = resourceList.ContentTypes.BestMatch(new SPContentTypeId("0x01005288A3160BABA04DAA0B8A015A3D490101"));

            if (!bestMatchScript.IsChildOf(scriptWebCTID))
            {
                SPContentType scriptCT = web.AvailableContentTypes[new SPContentTypeId("0x01005288A3160BABA04DAA0B8A015A3D490101")];
                resourceList.ContentTypes.Add(scriptCT);
            }

            SPContentTypeId styleWebCTID   = new SPContentTypeId("0x01005288A3160BABA04DAA0B8A015A3D490102");
            SPContentTypeId bestMatchStyle = resourceList.ContentTypes.BestMatch(styleWebCTID);

            if (!bestMatchStyle.IsChildOf(styleWebCTID))
            {
                SPContentType StyleCT = web.AvailableContentTypes[styleWebCTID];
                resourceList.ContentTypes.Add(StyleCT);
            }

            SPContentTypeId itemCTId = resourceList.ContentTypes.BestMatch(new SPContentTypeId("0x01"));

            resourceList.ContentTypes[itemCTId].Delete();

            resourceList.Update();

            // Set up default view
            SPView defaultView = resourceList.DefaultView;

            defaultView.Query = "<OrderBy><FieldRef Name=\"EvaluationOrder\" /></OrderBy>";
            if (!defaultView.ViewFields.Exists("EvaluationOrder"))
            {
                defaultView.ViewFields.Add("EvaluationOrder");
            }
            defaultView.Update();
        }
Example #9
0
        public void AddImplementedType(SPModelDescriptor descriptor)
        {
            CommonHelper.ConfirmNotNull(descriptor, "descriptor");
            foreach (SPModelDescriptor otherType in base.Children)
            {
                if (otherType != descriptor)
                {
                    foreach (SPFieldAttribute attribute in otherType.Fields)
                    {
                        descriptor.AddInterfaceDepenedentField(attribute);
                    }
                    foreach (SPFieldAttribute attribute in descriptor.Fields)
                    {
                        otherType.AddInterfaceDepenedentField(attribute);
                    }
                }
            }
            foreach (SPFieldAttribute attribute in descriptor.Fields)
            {
                AddRequiredViewField(attribute);
            }
            SPContentTypeId contentTypeId = descriptor.ContentTypeIds.First();

            foreach (SPModelDescriptor otherType in base.Children)
            {
                if (contentTypeId.IsChildOf(otherType.ContentTypeIds.First()))
                {
                    return;
                }
            }
            if (!baseType.HasValue)
            {
                baseType = descriptor.BaseType;
            }
            else if (baseType != descriptor.BaseType)
            {
                baseType = SPBaseType.UnspecifiedBaseType;
            }
            base.Children.Add(descriptor);
        }
 protected override void OnInit(EventArgs e)
 {
     //Check whether there in a SPContext, and if this is a List Item
     if (SPContext.Current != null && SPContext.Current.ListItem != null)
     {
         //Check whether the current content type is or inherits from the Page content type
         SPContentTypeId pageContentTypeId = SPContext.Current.Web.AvailableContentTypes["Page"].Id;
         SPContentTypeId currentItemTypeId = SPContext.Current.ListItem.ContentTypeId;
         if (currentItemTypeId.Equals(pageContentTypeId) || currentItemTypeId.IsChildOf(pageContentTypeId))
         {
             //Get the PageHolderMain content place holder control
             ContentPlaceHolder placeHolderMain = (ContentPlaceHolder)this.Page.Master.FindControl("PlaceHolderMain");
             if (placeHolderMain != null)
             {
                 //Check whether the current item is a publishing page and is a New item or in Edit mode
                 if ((PublishingPage.IsPublishingPage(SPContext.Current.ListItem)) &&
                     (SPContext.Current.FormContext.FormMode == SPControlMode.Edit ||
                      SPContext.Current.FormContext.FormMode == SPControlMode.New))
                 {
                     //Get the custom column
                     SPField demoCustomColumn;
                     try
                     {
                         demoCustomColumn = SPContext.Current.ListItem.Fields["DemoCustomColumn"];
                     }
                     catch
                     {
                         demoCustomColumn = null;
                     }
                     if (demoCustomColumn != null)
                     {
                         //We have a page, in edit or new mode, with the demoCustomColumn.
                         //So render the custom field control
                         BaseFieldControl demoCustomColumnControl = demoCustomColumn.FieldRenderingControl;
                         demoCustomColumnControl.ID = demoCustomColumn.InternalName;
                         placeHolderMain.Controls.Add(new LiteralControl("<div class=\"edit-mode-panel\">"));
                         placeHolderMain.Controls.Add(demoCustomColumnControl);
                         placeHolderMain.Controls.Add(new LiteralControl("</div>"));
                     }
                 }
                 else if ((PublishingPage.IsPublishingPage(SPContext.Current.ListItem)) &&
                          (SPContext.Current.FormContext.FormMode == SPControlMode.Display))
                 {
                     //Get the custom column
                     SPField demoCustomColumn;
                     try
                     {
                         demoCustomColumn = (SPFieldText)SPContext.Current.ListItem.Fields["DemoCustomColumn"];
                     }
                     catch
                     {
                         demoCustomColumn = null;
                     }
                     if (demoCustomColumn != null)
                     {
                         //We have a page, in display mode, with the demoCustomColumn.
                         //So render the value of the field. You can add custom rendering markup
                         //here. In this case, the <div> tag renders the text in red.
                         placeHolderMain.Controls.Add(new LiteralControl("<div style=\"color: red;\">"));
                         placeHolderMain.Controls.Add(new LiteralControl(SPContext.Current.ListItem["DemoCustomColumn"].ToString()));
                         placeHolderMain.Controls.Add(new LiteralControl("</div>"));
                     }
                 }
             }
         }
     }
     base.OnInit(e);
 }
        public override int IsMatch(SPList list, SPContentTypeId ctId, int ItemId)
        {
            if (ctId == null)
            {
                return(SearchMatchLevel.NONE);
            }
            switch (ItemType)
            {
            case GroupType.AllList:
            {
                if (!ctId.IsChildOf(SPBuiltInContentTypeId.Document))
                {
                    return(SearchMatchLevel.LIST_BY_GROUP);
                }
                break;
            }

            case GroupType.AllDocumentLibrary:
            {
                if (ctId.IsChildOf(SPBuiltInContentTypeId.Document))
                {
                    return(SearchMatchLevel.LIST_BY_GROUP);
                }
                break;
            }

            case GroupType.AllDiscusions:
            {
                if (ctId.IsChildOf(SPBuiltInContentTypeId.Discussion))
                {
                    return(SearchMatchLevel.ITEM_BY_GROUP);
                }
                break;
            }

            case GroupType.AllMessages:
            {
                if (ctId.IsChildOf(SPBuiltInContentTypeId.Message))
                {
                    return(SearchMatchLevel.ITEM_BY_GROUP);
                }
                break;
            }

            case GroupType.AllBlogComments:
            {
                if ((ctId.IsChildOf(SPBuiltInContentTypeId.BlogComment)))
                {
                    return(SearchMatchLevel.ITEM_BY_GROUP);
                }
                break;
            }

            case GroupType.AllBlogPosts:
            {
                if (ctId.IsChildOf(SPBuiltInContentTypeId.BlogPost))
                {
                    return(SearchMatchLevel.ITEM_BY_GROUP);
                }
                break;
            }

            case GroupType.AllTasks:
            {
                if (ctId.IsChildOf(SPBuiltInContentTypeId.Task))
                {
                    return(SearchMatchLevel.ITEM_BY_GROUP);
                }
                break;
            }
            }
            //case Core.ItemType.MyTask: return ((obj is SPListItem) && ((SPListItem)obj).ContentType.Id.IsChildOf((SPBuiltInContentTypeId.Task))&&(((SPListItem)obj)[]));
            return(SearchMatchLevel.NONE);
        }
Example #12
0
 /// <summary>
 /// Получить сервис назначения прав
 /// </summary>
 /// <param name="id">Айди контентного типа элемента</param>
 /// <returns><see cref="IElementPermissionsAssigner"/></returns>
 public IElementPermissionsAssigner GetAssignerService(SPContentTypeId id)
 {
     return(this.assignerServices.FirstOrDefault(x => id.IsChildOf(x.ContentTypeId)));
 }
Example #13
0
        private void btnAddCt_Click(object sender, EventArgs e)
        {
            try
            {
                //TODO: add validate button
                SPContentType newCT = ((ContentTypeHolder)cboRootContentTypes.SelectedItem).CT;
                RichTextBox   rtb   = ActionMetadata.DefInstance.rtbDisplay;
                rtb.Clear();
                AddToRtbLocal("Adding Content Type to Document Library " + m_docLib.Title + "...\r\n", StyleType.titleSeagreen);

                //--
                if (!m_docLib.ContentTypesEnabled)
                {
                    m_docLib.ContentTypesEnabled = true;
                    m_docLib.Update();
                    AddToRtbLocal("Content Type management enabled for " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen);
                }

                //--
                bool found = false;
                foreach (SPContentType ct in m_docLib.ContentTypes)
                {
                    if (ct.Name == newCT.Name)
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    m_docLib.ContentTypes.Add(newCT);
                    AddToRtbLocal("Content Type " + newCT.Name + " added to " + m_docLib.Title + "\r\n", StyleType.bodySeaGreen);
                }
                else
                {
                    AddToRtbLocal("Content Type " + newCT.Name + " was already previously added to " + m_docLib.Title + "\r\n", StyleType.bodyChocolate);
                }

                GlobalVars.SETTINGS.metadata_defaultContentTypeForApplyCT = newCT.Group + " - " + newCT.Name;

                //--
                if (chkChangeAllDocumentsToContentType.Checked)
                {
                    int counter = 0;
                    AddToRtbLocal("Changing all documents in library to new ContentType\r\n", StyleType.bodyBlack);
                    FrmCancelRunning.ToggleEnabled(true);  //ActionMetadata.DefInstance.toggleEnabled(true);
                    for (int i = 0; i <= m_docLib.Items.Count - 1; i++)
                    {
                        if (GlobalVars.CancelRunning)
                        {
                            throw new Eh.CancelException();
                        }

                        SPListItem      listitem             = m_docLib.Items[i];
                        SPContentTypeId currentContentTypeId = (SPContentTypeId)listitem["ContentTypeId"];

                        if (!currentContentTypeId.IsChildOf(newCT.Id))
                        {
                            listitem["ContentTypeId"] = newCT.Id;
                            listitem.Update();
                            counter++;
                            AddToRtbLocal(listitem.File.Name, StyleType.bodySeaGreen);
                            AddToRtbLocal(" ContentType-> " + newCT.Name + "\r\n", StyleType.bodyBlack);
                            SmartStepUtil.ScrollToBottom(rtb);
                            Application.DoEvents();
                        }
                    }
                    AddToRtbLocal("STATS: changed ContentType for " + counter + " documents, " + " total items in library: " + m_docLib.Items.Count + "\r\n", StyleType.bodyDarkGray);
                }

                SmartStepUtil.AddToRTB(rtb, "Done\r\n", Color.Black, 10, true);
                //--
                this.Close();
            }
            catch (Eh.CancelException)
            {
                AddToRtbLocal("canceled by user\r\n", StyleType.bodyBlackBold);
            }
            catch (Exception ex)
            {
                Eh.GlobalErrorHandler(ex);
            }
            finally
            {
                //ActionMetadata.DefInstance.toggleEnabled(false);
                FrmCancelRunning.ToggleEnabled(false);
            }
        }
Example #14
0
        private static bool Check(SPContentTypeId id, string baseIdString)
        {
            var id2 = new SPContentTypeId(baseIdString);

            return(id == id2 || id.IsChildOf(id2));
        }