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


C# Web.GetFieldById方法代码示例

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


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

示例1: ProvisionObjects

        public override void ProvisionObjects(Web web, ProvisioningTemplate template)
        {
            var parser = new TokenParser(web);

            if (!web.IsPropertyAvailable("ServerRelativeUrl"))
            {
                web.Context.Load(web, w => w.ServerRelativeUrl);
                web.Context.ExecuteQuery();
            }

            web.Context.Load(web.Lists, lc => lc.IncludeWithDefaultProperties(l => l.RootFolder.ServerRelativeUrl));
            web.Context.ExecuteQuery();

            //TODO: Upgrade to SharePoint.Client v16.0 so refactoring can be done (uncomment following line when done!)
            //var existingLists = web.Lists.Select(existingList => existingList.RootFolder.ServerRelativeUrl).ToList();
            var existingLists = web.Lists.AsEnumerable().Select(existingList => existingList.RootFolder.ServerRelativeUrl).ToList();
            var serverRelativeUrl = web.ServerRelativeUrl;

            foreach (var list in template.Lists)
            {
                if (!existingLists.Contains(UrlUtility.Combine(serverRelativeUrl, list.Url)))
                {
                    var listCreate = new ListCreationInformation();
                    listCreate.Description = list.Description;
                    listCreate.TemplateType = list.TemplateType;
                    listCreate.Title = list.Title;
                    listCreate.QuickLaunchOption = list.OnQuickLaunch ? QuickLaunchOptions.On : QuickLaunchOptions.Off;
                    listCreate.Url = parser.Parse(list.Url);

                    var createdList = web.Lists.Add(listCreate);

                    createdList.EnableVersioning = list.EnableVersioning;
                    if (!String.IsNullOrEmpty(list.DocumentTemplate))
                    {
                        createdList.DocumentTemplateUrl = parser.Parse(list.DocumentTemplate);
                    }
                    createdList.Hidden = list.Hidden;
                    createdList.ContentTypesEnabled = list.ContentTypesEnabled;

                    createdList.Update();

                    web.Context.ExecuteQuery();

                    // TODO: handle 'removedefaultcontenttype'

                    foreach (var ctBinding in list.ContentTypeBindings)
                    {
                        createdList.AddContentTypeToListById(ctBinding.ContentTypeID);
                        if (ctBinding.Default)
                        {
                            createdList.SetDefaultContentTypeToList(ctBinding.ContentTypeID);
                        }
                    }

                    if (list.Fields.Any())
                    {
                        foreach (var field in list.Fields)
                        {
                            // Double check that the content type did not include the field before adding it in
                            if (!createdList.FieldExistsById(field.SchemaXml.Substring(field.SchemaXml.IndexOf("ID=\"{") + 5, 36)))
                            {
                                var fieldXml = parser.Parse(field.SchemaXml);
                                createdList.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.DefaultValue);
                            }
                        }
                        createdList.Update();
                        web.Context.ExecuteQuery();
                    }

                    if (list.FieldRefs.Any())
                    {
                        foreach (var fieldRef in list.FieldRefs)
                        {
                            var field = web.GetFieldById<Field>(fieldRef.ID);
                            if (!createdList.FieldExistsById(fieldRef.ID))
                            {
                                createdList.Fields.Add(field);
                            }

                        }
                        createdList.Update();
                        web.Context.ExecuteQuery();
                    }

                    foreach (var view in list.Views)
                    {

                        var viewDoc = XDocument.Parse(view.SchemaXml);

                        var displayNameXml = viewDoc.Root.Attribute("DisplayName");
                        if (displayNameXml == null)
                        {
                            throw new ApplicationException("Invalid View element, missing a valid value for the attribute DisplayName.");
                        }
                        var viewTitle = displayNameXml.Value;

                        // Type
                        var viewTypeString = viewDoc.Root.Attribute("Type") != null ? viewDoc.Root.Attribute("Type").Value : "None";
                        viewTypeString = viewTypeString[0].ToString().ToUpper() + viewTypeString.Substring(1).ToLower();
                        var viewType = (ViewType)Enum.Parse(typeof(ViewType), viewTypeString);
//.........这里部分代码省略.........
开发者ID:xaviayala,项目名称:Birchman,代码行数:101,代码来源:ObjectListInstance.cs

示例2: CreateRegistrationSiteColumns

        private static IEnumerable<Field> CreateRegistrationSiteColumns(Web web) {
            var fields = new List<Field>();
            var fieldsXml = new Dictionary<string, string>();

            #region Create Registration Site Columns

            // Build site columns for event registration list
            List<KeyValuePair<string, string>> additionalAttributes = new List<KeyValuePair<string, string>>();
            additionalAttributes.Add(new KeyValuePair<string, string>("ReadOnly", "TRUE"));
            additionalAttributes.Add(new KeyValuePair<string, string>("Customization", ""));
            fieldsXml.Add(Registration.FIELD_DATE,
                FormatField(
                new Guid("{E08894EF-5770-4DC4-936C-B9ED1E901F85}"),
                Registration.FIELD_DATE,
                FieldType.DateTime,
                "Registration Date",
                ListDetails.CorporateEventsSiteColumnsGroup,
                false,
                additionalAttributes));

            additionalAttributes = new List<KeyValuePair<string, string>>();
            additionalAttributes.Add(new KeyValuePair<string, string>("MaxLength", "50"));
            additionalAttributes.Add(new KeyValuePair<string, string>("Customization", ""));
            fieldsXml.Add(Registration.FIELD_FIRST_NAME,
                FormatField(
                new Guid("{16059CB2-353A-4FF3-A8CE-9E43C3D56C7D}"),
                Registration.FIELD_FIRST_NAME,
                FieldType.Text,
                "First Name",
                ListDetails.CorporateEventsSiteColumnsGroup,
                true,
                additionalAttributes));

            additionalAttributes = new List<KeyValuePair<string, string>>();
            additionalAttributes.Add(new KeyValuePair<string, string>("MaxLength", "50"));
            additionalAttributes.Add(new KeyValuePair<string, string>("Customization", ""));
            fieldsXml.Add(Registration.FIELD_LAST_NAME,
                FormatField(
                new Guid("{14C25003-ABC4-48CE-A4FB-3C7631CF4FBC}"),
                Registration.FIELD_LAST_NAME,
                FieldType.Text,
                "Last Name",
                ListDetails.CorporateEventsSiteColumnsGroup,
                true,
                additionalAttributes));

            additionalAttributes = new List<KeyValuePair<string, string>>();
            additionalAttributes.Add(new KeyValuePair<string, string>("MaxLength", "25"));
            additionalAttributes.Add(new KeyValuePair<string, string>("Customization", ""));
            fieldsXml.Add(Registration.FIELD_USER_ID,
                FormatField(
                new Guid("{695DE7E3-2BAD-4CA2-A10B-DCF4DED6626B}"),
                Registration.FIELD_USER_ID,
                FieldType.Text,
                "User Id",
                ListDetails.CorporateEventsSiteColumnsGroup,
                true,
                additionalAttributes));

            additionalAttributes = new List<KeyValuePair<string, string>>();
            additionalAttributes.Add(new KeyValuePair<string, string>("Customization", ""));
            fieldsXml.Add(Registration.FIELD_USER_EMAIL,
                FormatField(
                new Guid("{07042CA2-49D9-4C31-A932-47AF619EF8E5}"),
                Registration.FIELD_USER_EMAIL,
                FieldType.Text,
                "Email",
                ListDetails.CorporateEventsSiteColumnsGroup,
                true,
                additionalAttributes));

            TryCreateFields(web, fields, fieldsXml);

            var eventIdField = web.GetFieldById<Field>(Event.RegisteredEventFieldId);
            eventIdField.Required = true;
            eventIdField.Update();
            fields.Add(eventIdField);
            #endregion

            return fields;
        }   
开发者ID:Calisto1980,项目名称:PnP,代码行数:81,代码来源:DataInitializer.cs

示例3: EnsureSiteColumn

 public static Field EnsureSiteColumn(Web root, Guid fieldID, string fieldAsXml)
 {
     Field existingField = root.GetFieldById<Field>(fieldID);
     if (existingField != null)
     {
         return existingField;
     }
     Field newField = root.CreateField(fieldAsXml, true);
     return newField;
 }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:10,代码来源:Helper.cs


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