当前位置: 首页>>代码示例>>C#>>正文


C# ContentType.Update方法代码示例

本文整理汇总了C#中ContentType.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ContentType.Update方法的具体用法?C# ContentType.Update怎么用?C# ContentType.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentType的用法示例。


在下文中一共展示了ContentType.Update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateWingtipContentTypes

        static void CreateWingtipContentTypes()
        {
            ctypeProduct = CreateContentType("Product", "0x01");

              // add site columns
              FieldLinkCreationInformation fieldLinkProductCode = new FieldLinkCreationInformation();
              fieldLinkProductCode.Field = fieldProductCode;
              ctypeProduct.FieldLinks.Add(fieldLinkProductCode);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductListPrice = new FieldLinkCreationInformation();
              fieldLinkProductListPrice.Field = fieldProductListPrice;
              ctypeProduct.FieldLinks.Add(fieldLinkProductListPrice);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductCategory = new FieldLinkCreationInformation();
              fieldLinkProductCategory.Field = fieldProductCategory;
              ctypeProduct.FieldLinks.Add(fieldLinkProductCategory);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductColor = new FieldLinkCreationInformation();
              fieldLinkProductColor.Field = fieldProductColor;
              ctypeProduct.FieldLinks.Add(fieldLinkProductColor);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkMinimumAge = new FieldLinkCreationInformation();
              fieldLinkMinimumAge.Field = fieldMinimumAge;
              ctypeProduct.FieldLinks.Add(fieldLinkMinimumAge);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkMaximumAge = new FieldLinkCreationInformation();
              fieldLinkMaximumAge.Field = fieldMaximumAge;
              ctypeProduct.FieldLinks.Add(fieldLinkMaximumAge);
              ctypeProduct.Update(true);
              clientContext.ExecuteQuery();

              Console.WriteLine("Create Product Proposal content type");
              ctypeProductProposal = CreateContentType("Product Proposal", "0x0101");
              clientContext.Load(ctypeProductProposal);
              clientContext.ExecuteQuery();

              Console.WriteLine("Create Product Proposal folder in _cts folder");
              ListItemCreationInformation folder = new ListItemCreationInformation();
              site.RootFolder.Folders.Add("_cts/Product Proposal");
              clientContext.ExecuteQuery();

              Console.WriteLine("Update doc template file for content type");
              FileCreationInformation newFile = new FileCreationInformation();
              newFile.Content = System.IO.File.ReadAllBytes(studentFolder + @"Modules\DocumentLibraries\Lab\DocumentTemplates\WingtipProductProposal.dotx");
              newFile.Url = @"_cts/Product Proposal/WingtipProductProposal.dotx";
              newFile.Overwrite = true;
              Microsoft.SharePoint.Client.File uploadFile = site.RootFolder.Files.Add(newFile);
              clientContext.Load(uploadFile);
              clientContext.ExecuteQuery();

              Console.WriteLine("Assign doc template url to content type");
              ctypeProductProposal.DocumentTemplate =  siteUrl +  @"/_cts/Product Proposal/WingtipProductProposal.dotx";
              ctypeProductProposal.Update(true);
              clientContext.ExecuteQuery();
        }
开发者ID:CriticalPathTraining,项目名称:BBS2013,代码行数:60,代码来源:Program.cs

示例2: CreateProductContentType

        static void CreateProductContentType()
        {
            Console.WriteLine("Creating Product content type...");
              ctypeProduct = CreateContentType("Product", "0x01");

              // add site columns
              FieldLinkCreationInformation fieldLinkProductCode = new FieldLinkCreationInformation();
              fieldLinkProductCode.Field = fieldProductCode;
              ctypeProduct.FieldLinks.Add(fieldLinkProductCode);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductDescription = new FieldLinkCreationInformation();
              fieldLinkProductDescription.Field = fieldProductDescription;
              ctypeProduct.FieldLinks.Add(fieldLinkProductDescription);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductListPrice = new FieldLinkCreationInformation();
              fieldLinkProductListPrice.Field = fieldProductListPrice;
              ctypeProduct.FieldLinks.Add(fieldLinkProductListPrice);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkProductColor = new FieldLinkCreationInformation();
              fieldLinkProductColor.Field = fieldProductColor;
              ctypeProduct.FieldLinks.Add(fieldLinkProductColor);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkMinimumAge = new FieldLinkCreationInformation();
              fieldLinkMinimumAge.Field = fieldMinimumAge;
              ctypeProduct.FieldLinks.Add(fieldLinkMinimumAge);
              ctypeProduct.Update(true);

              FieldLinkCreationInformation fieldLinkMaximumAge = new FieldLinkCreationInformation();
              fieldLinkMaximumAge.Field = fieldMaximumAge;
              ctypeProduct.FieldLinks.Add(fieldLinkMaximumAge);
              ctypeProduct.Update(true);
              clientContext.ExecuteQuery();
        }
开发者ID:CriticalPathTraining,项目名称:BBS365,代码行数:37,代码来源:Program.cs

示例3: DeployContentTypeWorkflowAssociationDefinition

        private void DeployContentTypeWorkflowAssociationDefinition(object modelHost, ContentType contentType, WorkflowAssociationDefinition definition)
        {
            var context = contentType.Context;
            var web = (modelHost as ModelHostContext).Web;

            var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = existingWorkflowAssotiation,
                ObjectType = typeof(WorkflowAssociation),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (existingWorkflowAssotiation == null
                ||
                (existingWorkflowAssotiation.ServerObjectIsNull.HasValue &&
                 existingWorkflowAssotiation.ServerObjectIsNull.Value))
            {
                var workflowTemplate = GetWorkflowTemplate(modelHost, definition);

                if (workflowTemplate == null ||
                    (workflowTemplate.ServerObjectIsNull.HasValue && workflowTemplate.ServerObjectIsNull.Value))
                {
                    throw new SPMeta2Exception(
                        string.Format("Cannot find workflow template by definition:[{0}]", definition));
                }

                var historyList = web.QueryAndGetListByTitle(definition.HistoryListTitle);
                var taskList = web.QueryAndGetListByTitle(definition.TaskListTitle);

                var newWorkflowAssotiation = contentType.WorkflowAssociations.Add(new WorkflowAssociationCreationInformation
                {
                    Name = definition.Name,
                    Template = workflowTemplate,
                    HistoryList = historyList,
                    TaskList = taskList
                });

                MapProperties(definition, newWorkflowAssotiation);

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = newWorkflowAssotiation,
                    ObjectType = typeof(WorkflowAssociation),
                    ObjectDefinition = definition,
                    ModelHost = modelHost
                });

                contentType.Update(true);
                context.ExecuteQueryWithTrace();
            }
            else
            {
                MapProperties(definition, existingWorkflowAssotiation);

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = existingWorkflowAssotiation,
                    ObjectType = typeof(WorkflowAssociation),
                    ObjectDefinition = definition,
                    ModelHost = modelHost
                });

                // no update
                // gives weird null ref exception

                // Enhance WorkflowAssociationDefinition - add more tests on updatability #871
                // https://github.com/SubPointSolutions/spmeta2/issues/871

                //existingWorkflowAssotiation.Update();

                contentType.Update(true);
                context.ExecuteQueryWithTrace();
            }
        }
开发者ID:maratbakirov,项目名称:spmeta2,代码行数:86,代码来源:WorkflowAssociationModelHandler.cs

示例4: RemoveFieldFromContentType

        private void RemoveFieldFromContentType(FieldCollection webFields, string fieldNameToRemove,
            ContentType contentType)
        {
            // Need to load content type fields every iteration because fields are added to the collection
            Field webField = webFields.GetByInternalNameOrTitle(fieldNameToRemove);
            FieldLinkCollection contentTypeFields = contentType.FieldLinks;
            ClientContext.Load(contentTypeFields);
            ClientContext.Load(webField);
            ClientContext.ExecuteQuery();

            var fieldLink =
                contentTypeFields.FirstOrDefault(
                    existingFieldName => existingFieldName.Name == fieldNameToRemove);
            if (fieldLink != null)
            {
                fieldLink.DeleteObject();
            }
            contentType.Update(true);
            ClientContext.ExecuteQuery();
        }
开发者ID:olemp,项目名称:sherpa,代码行数:20,代码来源:ContentTypeManager.cs

示例5: AddOrUpdateFieldOfContentType

        private void AddOrUpdateFieldOfContentType(ShContentType configContentType, FieldCollection webFields,
            string fieldName,
            ContentType contentType)
        {
            // Need to load content type fields every iteration because fields are added to the collection
            Field webField = webFields.GetByInternalNameOrTitle(fieldName);
            FieldLinkCollection contentTypeFields = contentType.FieldLinks;
            ClientContext.Load(contentTypeFields);
            ClientContext.Load(webField);
            ClientContext.ExecuteQuery();

            var fieldLink = contentTypeFields.FirstOrDefault(existingFieldName => existingFieldName.Name == fieldName);
            if (fieldLink == null)
            {
                var link = new FieldLinkCreationInformation {Field = webField};
                fieldLink = contentType.FieldLinks.Add(link);
            }

            fieldLink.Required = configContentType.RequiredFields.Contains(fieldName);
            fieldLink.Hidden = configContentType.HiddenFields.Contains(fieldName);

            contentType.Update(true);
            ClientContext.ExecuteQuery();
        }
开发者ID:olemp,项目名称:sherpa,代码行数:24,代码来源:ContentTypeManager.cs

示例6: AddColumnsToContentType

 /// <summary>
 /// Method to add columns to Content Type
 /// </summary>
 /// <param name="web">Object of site</param>
 /// <param name="siteColumns">List of site columns</param>
 /// <param name="finalObj">Content type to which columns are to be added</param>
 /// <returns>Success or Failure</returns>
 private static bool AddColumnsToContentType(Web web, List<string> siteColumns, ContentType finalObj)
 {
     try
     {
         FieldCollection fieldCol = web.Fields;
         foreach (string columns in siteColumns)
         {
             bool isColumnExists = (null != finalObj.Fields.Where(field => field.Title.Equals(columns, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()) ? true : false;
             if (!isColumnExists)
             {
                 Field customDoc = fieldCol.GetByTitle(columns);
                 FieldLinkCreationInformation fieldCreationInformation = new FieldLinkCreationInformation();
                 fieldCreationInformation.Field = customDoc;
                 finalObj.FieldLinks.Add(fieldCreationInformation);
             }
         }
         finalObj.Update(true);
         return true;
     }
     catch (Exception exception)
     {
         ErrorLogger.LogErrorToTextFile(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
         return false;
     }
 }
开发者ID:Microsoft,项目名称:mattercenter,代码行数:32,代码来源:CreateSiteColumns.cs

示例7: BindFieldsToContentType

        /// <summary>
        /// Add existed site columns to
        /// target content type
        /// </summary>
        public static void BindFieldsToContentType(ClientContext clientContext, ContentType contentType, string[] filedNames)
        {
            var fields = clientContext.Web.Fields;

            foreach (string fieldName in filedNames)
            {
                var field = fields.GetByInternalNameOrTitle(fieldName);
                clientContext.Load(field);
                clientContext.ExecuteQuery();

                contentType.FieldLinks.Add(new FieldLinkCreationInformation
                {
                    Field = field
                });
                contentType.Update(true);
                clientContext.ExecuteQuery();
            }
        }
开发者ID:TBag,项目名称:Property-Inspection-Code-Sample,代码行数:22,代码来源:CSOMUtil.cs

示例8: AddFieldToContentType

        /// <summary>
        /// 
        /// </summary>
        /// <param name="web"></param>
        /// <param name="contentType"></param>
        /// <param name="field"></param>
        /// <param name="required"></param>
        /// <param name="hidden"></param>
        public static void AddFieldToContentType(this Web web, ContentType contentType, Field field, bool required = false, bool hidden = false)
        {
            FieldLinkCreationInformation fldInfo = new FieldLinkCreationInformation();
            fldInfo.Field = field;
            contentType.FieldLinks.Add(fldInfo);
            contentType.Update(true);
            web.Context.ExecuteQuery();

            web.Context.Load(field);
            web.Context.ExecuteQuery();

            if (required || hidden)
            {
                //Update FieldLink
                FieldLink flink = contentType.FieldLinks.GetById(field.Id);
                flink.Required = required;
                flink.Hidden = hidden;
                contentType.Update(true);
                web.Context.ExecuteQuery();
            }
        }
开发者ID:usmanfast,项目名称:PnP,代码行数:29,代码来源:FieldAndContentTypeExtensions.cs

示例9: AddColumnsToContentType

 /// <summary>
 /// Add columns to content type.
 /// </summary>
 /// <param name="web">Object of site</param>
 /// <param name="siteColumns">List of site columns</param>
 /// <param name="finalObj">Content type to which columns are to be added</param>        
 internal static void AddColumnsToContentType(Microsoft.SharePoint.Client.Web web, List<string> siteColumns, ContentType finalObj)
 {
     try
     {
         FieldCollection fieldCol = web.Fields;
         foreach (string columns in siteColumns)
         {
             Field customDoc = (from fld in fieldCol
                                where fld.Title == columns && fld.TypeAsString == ServiceConstantStrings.OneDriveSiteColumnType
                                select fld).FirstOrDefault();
             FieldLinkCreationInformation fieldLinkCreationInfo = new FieldLinkCreationInformation();
             fieldLinkCreationInfo.Field = customDoc;
             finalObj.FieldLinks.Add(fieldLinkCreationInfo);
         }
         finalObj.Update(true);
     }
     catch (Exception exception)
     {
         Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
     }
 }
开发者ID:MatthewSammut,项目名称:mattercenter,代码行数:27,代码来源:BriefcaseContentTypeHelperFunctions.cs

示例10: CreateResearchContentTypes

        static void CreateResearchContentTypes()
        {
            Console.WriteLine("Creating Product Proposal content type...");
              ctypeProductProposal = CreateContentType("Product Proposal", "0x0101");

              ListItemCreationInformation folder = new ListItemCreationInformation();
              site.RootFolder.Folders.Add("_cts/Product Proposal");
              clientContext.ExecuteQuery();

              FileCreationInformation newFile = new FileCreationInformation();
              newFile.Content = Properties.Resources.WingtipProductProposal_dotx;
              newFile.Url = @"_cts/Product Proposal/WingtipProductProposal.dotx";
              newFile.Overwrite = true;
              Microsoft.SharePoint.Client.File uploadFile = site.RootFolder.Files.Add(newFile);
              clientContext.Load(uploadFile);
              clientContext.ExecuteQuery();

              ctypeProductProposal.DocumentTemplate = siteUrl + @"/_cts/Product Proposal/WingtipProductProposal.dotx";
              ctypeProductProposal.Update(true);
              clientContext.ExecuteQuery();

              Console.WriteLine("Creating Product Plan Status Report content type...");
              ctypeProductPlanStatusReport = CreateContentType("Product Plan Status Report", "0x0101");

              folder = new ListItemCreationInformation();
              site.RootFolder.Folders.Add("_cts/Product Plan Status Report");
              clientContext.ExecuteQuery();

              newFile = new FileCreationInformation();
              newFile.Content = Properties.Resources.WingtipProductPlanStatusReport_dotx;
              newFile.Url = @"_cts/Product Plan Status Report/WingtipProductPlanStatusReport.dotx";
              newFile.Overwrite = true;
              uploadFile = site.RootFolder.Files.Add(newFile);
              clientContext.Load(uploadFile);
              clientContext.ExecuteQuery();

              ctypeProductPlanStatusReport.DocumentTemplate = siteUrl + @"/_cts/Product Plan Status Report/WingtipProductPlanStatusReport.dotx";
              ctypeProductPlanStatusReport.Update(true);
              clientContext.ExecuteQuery();

              Console.WriteLine("Creating Product Plan Document Set content type...");
              ctypeProductPlanDocucmentSet = CreateContentType("Product Plan Document Set", ctypeIdDocumentSet);
              clientContext.ExecuteQuery();

              //// copy files
              FileCreationInformation infoDefaultFile1 = new FileCreationInformation();
              infoDefaultFile1.Content = Properties.Resources.Product_Design_Specification_docx;
              infoDefaultFile1.Url = siteUrl + @"_cts/Product Plan Document Set/Product Design Specification.docx";
              infoDefaultFile1.Overwrite = true;
              uploadFile = site.RootFolder.Files.Add(infoDefaultFile1);
              clientContext.ExecuteQuery();

              FileCreationInformation infoDefaultFile2 = new FileCreationInformation();
              infoDefaultFile2.Content = Properties.Resources.Product_Plan_Schedule_xlsx;
              infoDefaultFile2.Url = siteUrl + @"_cts/Product Plan Document Set/Product Plan Schedule.xlsx";
              infoDefaultFile2.Overwrite = true;
              Microsoft.SharePoint.Client.File uploadFile2 = site.RootFolder.Files.Add(infoDefaultFile2);
              clientContext.ExecuteQuery();

              clientContext.Load(ctypeProductPlanDocucmentSet, ctype => ctype.SchemaXmlWithResourceTokens);
              clientContext.ExecuteQuery();

              XElement elementCTypeSchema = XElement.Parse(ctypeProductPlanDocucmentSet.SchemaXmlWithResourceTokens);

              // add default documents
              XElement elementDefaultDocuments = elementCTypeSchema.Descendants().Single(node => (node.Name == "XmlDocument") &&  (node.FirstAttribute.ToString() == @"NamespaceURI=""http://schemas.microsoft.com/office/documentsets/defaultdocuments"""));
              string xmlDefaultDocuments = @"<dd:DefaultDocuments xmlns:dd='http://schemas.microsoft.com/office/documentsets/defaultdocuments' AddSetName='True' LastModified='01/01/0001'><DefaultDocument name='/Product Design Specification.docx' idContentType='0x0101' /><DefaultDocument name='/Product Plan Schedule.xlsx' idContentType='0x0101' /></dd:DefaultDocuments>";
              elementDefaultDocuments.Value = ConvertToBase64EncodedString(xmlDefaultDocuments);

              // add allowed content types
              XElement elementAllowedContentTypes = elementCTypeSchema.Descendants().Single(node => (node.Name == "XmlDocument") && (node.FirstAttribute.ToString() == @"NamespaceURI=""http://schemas.microsoft.com/office/documentsets/allowedcontenttypes"""));
              string xmlAllowedContentTypes = @"<act:AllowedContentTypes xmlns:act='http://schemas.microsoft.com/office/documentsets/allowedcontenttypes' LastModified='01/01/0001'><AllowedContentType id='0x0101'/><AllowedContentType id='@ctypeTypeIdProductPlanStatusReport'/></act:AllowedContentTypes>";
              clientContext.Load(ctypeProductPlanStatusReport, ct => ct.Id);
              clientContext.ExecuteQuery();
              xmlAllowedContentTypes = xmlAllowedContentTypes.Replace("@ctypeTypeIdProductPlanStatusReport", ctypeProductPlanStatusReport.Id.StringValue);
              elementAllowedContentTypes.Value = ConvertToBase64EncodedString(xmlAllowedContentTypes);

              string xmlSharedFields = @"<sf:SharedFields xmlns:sf='http://schemas.microsoft.com/office/documentsets/sharedfields' LastModified='01/01/0001'><SharedField id='@idProposedProductCode' /></sf:SharedFields>";

              string xmlWelcomePageFields = @"<wpf:WelcomePageFields xmlns:wpf='http://schemas.microsoft.com/office/documentsets/welcomepagefields' LastModified='01/01/0001'><WelcomePageField id='idProposedProductCode' /><WelcomePageField id='idEstimatedCompletionDate' /></wpf:WelcomePageFields>";

              // save the edited schema back into the site
              ctypeProductPlanDocucmentSet.SchemaXmlWithResourceTokens = elementCTypeSchema.ToString(SaveOptions.DisableFormatting);
              ctypeProductPlanDocucmentSet.Update(true);
              clientContext.ExecuteQuery();
        }
开发者ID:CriticalPathTraining,项目名称:BBS2013,代码行数:86,代码来源:Program.cs


注:本文中的ContentType.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。