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


C# ClientContext.Load方法代码示例

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


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

示例1: AddHtmlToWikiPage

        public void AddHtmlToWikiPage(ClientContext ctx, Web web, string folder, string html, string page)
        {
            Microsoft.SharePoint.Client.Folder pagesLib = web.GetFolderByServerRelativeUrl(folder);
            ctx.Load(pagesLib.Files);
            ctx.ExecuteQuery();

            Microsoft.SharePoint.Client.File wikiPage = null;

            foreach (Microsoft.SharePoint.Client.File aspxFile in pagesLib.Files)
            {
                if (aspxFile.Name.Equals(page, StringComparison.InvariantCultureIgnoreCase))
                {
                    wikiPage = aspxFile;
                    break;
                }
            }

            if (wikiPage == null)
            {
                return;
            }

            ctx.Load(wikiPage);
            ctx.Load(wikiPage.ListItemAllFields);
            ctx.ExecuteQuery();

            string wikiField = (string)wikiPage.ListItemAllFields["WikiField"];

            Microsoft.SharePoint.Client.ListItem listItem = wikiPage.ListItemAllFields;
            listItem["WikiField"] = html;
            listItem.Update();
            ctx.ExecuteQuery();
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:33,代码来源:Default.aspx.cs

示例2: Execute

        public void Execute(ClientContext ctx, string listTitle, XElement schema, Action<Field> setAdditionalProperties = null)
        {
            var displayName = schema.Attribute("DisplayName").Value;
            Logger.Verbose($"Started executing {nameof(CreateColumnOnList)} for column '{displayName}' on list '{listTitle}'");

            var list = ctx.Web.Lists.GetByTitle(listTitle);
            var fields = list.Fields;
            ctx.Load(fields);
            ctx.ExecuteQuery();

            // if using internal names in code, remember to encode those before querying, e.g., 
            // space character becomes "_x0020_" as described here:
            // http://www.n8d.at/blog/encode-and-decode-field-names-from-display-name-to-internal-name/
            // We don't use the internal name here because it's limited to 32 chacters. This means
            // "Secondary site abcde" is the longest possible internal name when taken into account
            // the "_x0020_" character. Using a longer name will truncate the internal name to 32
            // characters. Thus querying on the complete, not truncated name, will always return no
            // results which causes the field get created repetedly.
            var field = fields.SingleOrDefault(f => f.Title == displayName);
            if (field != null)
            {
                Logger.Warning($"Column '{displayName}' already on list {listTitle}");
                return;
            }

            var newField = list.Fields.AddFieldAsXml(schema.ToString(), true, AddFieldOptions.DefaultValue);
            ctx.Load(newField);
            ctx.ExecuteQuery();

            if (setAdditionalProperties != null)
            {
                setAdditionalProperties(newField);
                newField.Update();
            }
        }
开发者ID:ronnieholm,项目名称:Bugfree.Spo.Cqrs,代码行数:35,代码来源:CreateColumnOnList.cs

示例3: SetTaxonomyField

        /// <summary>
        /// Helper Method to set a Taxonomy Field on a list item
        /// </summary>
        /// <param name="ctx">The Authenticated ClientContext</param>
        /// <param name="listItem">The listitem to modify</param>
        /// <param name="model">Domain Object of key/value pairs of the taxonomy field & value</param>
        public static void SetTaxonomyField(ClientContext ctx, ListItem listItem, Hashtable model)
        {
          
            FieldCollection _fields = listItem.ParentList.Fields;
            ctx.Load(_fields);
            ctx.ExecuteQuery();

            foreach(var _key in model.Keys)
            {
               var _termName = model[_key].ToString();
               TaxonomyField _field = ctx.CastTo<TaxonomyField>(_fields.GetByInternalNameOrTitle(_key.ToString()));
               ctx.Load(_field);
               ctx.ExecuteQuery();
               Guid _id = _field.TermSetId;
               string _termID = AutoTaggingHelper.GetTermIdByName(ctx, _termName, _id );
               var _termValue = new TaxonomyFieldValue()
               {
                   Label = _termName,
                   TermGuid = _termID,
                   WssId = -1
               };

               _field.SetFieldValueByValue(listItem, _termValue);
               listItem.Update();
               ctx.ExecuteQuery();
            }
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:33,代码来源:AutoTaggingHelper.cs

示例4: Run

        public override int Run(string[] remainingArguments)
        {
            _log.Info("Connecting to {0}", _url);

            var ctx = new ClientContext(_url);
            _log.Info("Loading lists");
            var allLists = ctx.Web.Lists;
            ctx.Load(allLists);
            ctx.Load(ctx.Web);
            ctx.ExecuteQuery();

            var lists = allLists.ToList().Where(list => !list.IsCatalog).ToList();
            lists.ForEach(list => ctx.Load(list.Fields));
            ctx.ExecuteQuery();

            _log.Info("Exporting lists:");

            var data = lists.Select(list =>
                {
                    _log.Info("{0} ({1})", list.Title, list.ItemCount);
                    var fields =
                        list.Fields.ToList()
                            .Where(field => !_doNotWantFields.IsMatch(field.TypeAsString))
                            .Where(field => !field.ReadOnlyField)
                            .Select(field => field)
                            .ToList();

                    fields.Add(list.Fields.ToList().First(field => field.InternalName == "ID"));

                    var items = list.GetItems(new CamlQuery());
                    ctx.Load(items);
                    ctx.Load(list.RootFolder);
                    ctx.ExecuteQuery();

                    return new List
                        {
                            Name = list.RootFolder.Name,
                            Fields = fields.Select(field => field.InternalName).ToList(),
                            Items = items.ToList().Select(item => fields.Select(field =>
                                {
                                    var lValue = item[field.InternalName] as FieldLookupValue;
                                    if (lValue != null) return lValue.LookupId;
                                    var uValue = item[field.InternalName] as FieldUserValue;
                                    if (uValue != null) return uValue.LookupId;
                                    return item[field.InternalName];
                                }).ToList()).ToList()
                        };
                });

            var jss = new JavaScriptSerializer
                {
                    MaxJsonLength = int.MaxValue
                };
            var title = ctx.Web.Title;
            if (string.IsNullOrEmpty(title)) title = "NoName";
            _log.Info(title);
            File.WriteAllText(string.Format("{0}.json", title), jss.Serialize(data));
            _log.Info("Done. {0}", lists.Count);
            return 0;
        }
开发者ID:eirikb,项目名称:jsonlist,代码行数:60,代码来源:Export.cs

示例5: Main

        static void Main()
        {
            // get client context
              ClientContext clientContext = new ClientContext("http://intranet.wingtip.com");

              // create variables for CSOM objects
              Site siteCollection = clientContext.Site;
              Web site = clientContext.Web;
              ListCollection lists = site.Lists;

              // give CSOM instructions to populate objects
              clientContext.Load(siteCollection);
              clientContext.Load(site);
              clientContext.Load(lists);

              // make round-trip to SharePoint host to carry out instructions
              clientContext.ExecuteQuery();

              // CSOM object are now initialized
              Console.WriteLine(siteCollection.Id);
              Console.WriteLine(site.Title);
              Console.WriteLine(lists.Count);

              // retrieve another CSOM object
              List list = lists.GetByTitle("Documents");
              clientContext.Load(list);

              // make a second round-trip to SharePoint host
              clientContext.ExecuteQuery();

              Console.WriteLine(list.Title);

              Console.ReadLine();
        }
开发者ID:kimberpjub,项目名称:GSA2013,代码行数:34,代码来源:Program.cs

示例6: IsWebPartOnPage

        public static bool IsWebPartOnPage(ClientContext ctx, string relativePageUrl, string title)
        {
            var webPartPage = ctx.Web.GetFileByServerRelativeUrl(relativePageUrl);
            ctx.Load(webPartPage);
            ctx.ExecuteQuery();

            if (webPartPage == null)
            {
                return false;
            }

            LimitedWebPartManager limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
            ctx.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.WebPart.Title));
            ctx.ExecuteQueryRetry();

            if (limitedWebPartManager.WebParts.Count >= 0)
            {
                for (int i = 0; i < limitedWebPartManager.WebParts.Count; i++)
                {
                    WebPart oWebPart = limitedWebPartManager.WebParts[i].WebPart;
                    if (oWebPart.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:Rtoribiog,项目名称:PnP-Transformation,代码行数:29,代码来源:SetupManager.cs

示例7: CreateSearchNavigationNodes

        internal static void CreateSearchNavigationNodes(ClientContext clientContext, Web web, Dictionary<string, string> searchNavigationNodes)
        {
            if (searchNavigationNodes == null || searchNavigationNodes.Count == 0) return;

            var searchNavigation = web.Navigation.GetNodeById(1040);
            NavigationNodeCollection nodeCollection = searchNavigation.Children;

            clientContext.Load(searchNavigation);
            clientContext.Load(nodeCollection);
            clientContext.ExecuteQuery();

            for (int i = nodeCollection.Count - 1; i >= 0; i--)
            {
                nodeCollection[i].DeleteObject();
            }

            foreach (KeyValuePair<string, string> newNode in searchNavigationNodes.Reverse<KeyValuePair<string, string>>())
            {
                nodeCollection.Add(new NavigationNodeCreationInformation
                {
                    Title = newNode.Key,
                    Url = newNode.Value
                });
            }

            clientContext.ExecuteQuery();
        }
开发者ID:olemp,项目名称:sherpa,代码行数:27,代码来源:SearchNavigationManager.cs

示例8: GetTermIdByName

        /// <summary>
        /// Helper Methods to get a TermId by a Name
        /// </summary>
        /// <param name="ctx">The Authenticated ClientContext</param>
        /// <param name="term">The Term Name do lookup.</param>
        /// <param name="termSetId">The TermSet Guid</param>
        /// <returns></returns>
        public static string GetTermIdByName(ClientContext ctx, string term, Guid termSetId)
        {
            string _resultTerm = string.Empty;

            var _taxSession = TaxonomySession.GetTaxonomySession(ctx);
            var _termStore = _taxSession.GetDefaultSiteCollectionTermStore();
            var _termSet = _termStore.GetTermSet(termSetId);

            var _termMatch = new LabelMatchInformation(ctx)
            {
               Lcid = 1033,
               TermLabel = term,     
               TrimUnavailable = true
            };

            var _termCollection = _termSet.GetTerms(_termMatch);
            ctx.Load(_taxSession);
            ctx.Load(_termStore);
            ctx.Load(_termSet);
            ctx.Load(_termCollection);
            ctx.ExecuteQuery();

            if (_termCollection.Count() > 0)
                _resultTerm = _termCollection.First().Id.ToString();

            return _resultTerm;

        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:35,代码来源:AutoTaggingHelper.cs

示例9: AddPublishingPage

        public static void AddPublishingPage(PublishingPage page, ClientContext ctx, Web web)
        {
            SPPublishing.PublishingPage publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            RemovePublishingPage(publishingPage, page, ctx, web);

            web.AddPublishingPage(page.FileName, page.Layout, page.Title, false); //DO NOT Publish here or it will fail if library doesn't enable Minor versions (PnP bug)

            publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
            pageFile.CheckOut();

            if (page.Properties != null && page.Properties.Count > 0)
            {
                ctx.Load(pageFile, p => p.Name, p => p.CheckOutType); //need these values in SetFileProperties
                ctx.ExecuteQuery();
                pageFile.SetFileProperties(page.Properties, false);
            }

            if (page.WebParts != null && page.WebParts.Count > 0)
            {
                Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr = pageFile.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);

                ctx.Load(mgr);
                ctx.ExecuteQuery();

                AddWebpartsToPublishingPage(page, ctx, mgr);
            }

            List pagesLibrary = publishingPage.ListItem.ParentList;
            ctx.Load(pagesLibrary);
            ctx.ExecuteQueryRetry();

            ListItem pageItem = publishingPage.ListItem;
            web.Context.Load(pageItem, p => p.File.CheckOutType);
            web.Context.ExecuteQueryRetry();            

            if (pageItem.File.CheckOutType != CheckOutType.None)
            {
                pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
            }

            if (page.Publish && pagesLibrary.EnableMinorVersions)
            {
                pageItem.File.Publish(String.Empty);
                if (pagesLibrary.EnableModeration)
                {
                    pageItem.File.Approve(String.Empty);
                }
            }


            if (page.WelcomePage)
            {
                SetWelcomePage(web, pageFile);
            }

            ctx.ExecuteQuery();
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:60,代码来源:PageHelper.cs

示例10: UploadMasterPage

        public static void UploadMasterPage(ClientContext clientContext, string name, string folder) {
            var web = clientContext.Web;
            var lists = web.Lists;
            var gallery = web.GetCatalog(116);
            clientContext.Load(lists, l => l.Include(ll => ll.DefaultViewUrl));
            clientContext.Load(gallery, g => g.RootFolder.ServerRelativeUrl);
            clientContext.ExecuteQuery();

            Console.WriteLine("Uploading and applying {0} to {1}", name, web.ServerRelativeUrl);

            var masterPath = gallery.RootFolder.ServerRelativeUrl.TrimEnd(new char[] { '/' }) + "/";

            EnsureFolder(web, masterPath, folder);
            CheckOutFile(web, name, masterPath, folder);

            var uploadFile = AddFile(web.Url, web, "Branding\\MasterPages\\", name, masterPath, folder);

            SetMasterPageMetadata(web, uploadFile);
            CheckInPublishAndApproveFile(uploadFile);

            //store the currently used master pages so we can switch back upon deactivation
            var allWebProperties = web.AllProperties;
            allWebProperties["OriginalMasterUrl"] = web.MasterUrl;
            allWebProperties["CustomMasterUrl"] = web.CustomMasterUrl;

            var masterUrl = string.Concat(masterPath, folder, (string.IsNullOrEmpty(folder) ? string.Empty : "/"), name);
            web.MasterUrl = masterUrl;
            web.CustomMasterUrl = masterUrl;
            web.Update();
            clientContext.ExecuteQuery();
        }
开发者ID:CherifSy,项目名称:PnP,代码行数:31,代码来源:BrandingHelper.cs

示例11: Execute

        public void Execute(ClientContext ctx, string libraryName, string filePath)
        {
            Logger.Verbose($"Started executing {nameof(SetWelcomePage)} to '{filePath}' for library '{libraryName}'");

            var web = ctx.Web;
            var library = web.Lists.GetByTitle(libraryName);
            ctx.Load(library, l => l.RootFolder.ServerRelativeUrl, l => l.EntityTypeName);
            ctx.ExecuteQuery();

            var file = web.GetFileByServerRelativeUrl(library.RootFolder.ServerRelativeUrl + "/" + filePath);
            ctx.Load(file, f => f.Exists);
            ctx.ExecuteQuery();

            if (!file.Exists)
            {
                throw new InvalidOperationException($"File '{filePath}' not found in library '{library}'");
            }

            var rootFolder = web.RootFolder;
            ctx.Load(rootFolder);
            ctx.ExecuteQuery();

            var newWelcomePage = $"{library.EntityTypeName}/{filePath}";
            if (rootFolder.WelcomePage == newWelcomePage)
            {
                Logger.Warning("Welcome page has already been set");
                return;
            }

            rootFolder.WelcomePage = newWelcomePage;
            rootFolder.Update();
            ctx.ExecuteQuery();
        }
开发者ID:ronnieholm,项目名称:Bugfree.Spo.Cqrs,代码行数:33,代码来源:SetWelcomePage.cs

示例12: Execute

        public void Execute(ClientContext ctx, string listTitle, string viewTitle, string[] fields, Action<View> setAdditionalProperties = null)
        {
            Logger.Verbose($"Started executing {nameof(CreateListView)} for view '{viewTitle}' on list '{listTitle}'");

            ctx.Load(ctx.Web.Lists);
            ctx.ExecuteQuery();

            var l = ctx.Web.Lists.GetByTitle(listTitle);
            ctx.Load(l, x => x.Views);
            ctx.ExecuteQuery();

            var view = l.Views.SingleOrDefault(v => v.Title == viewTitle);
            if (view != null)
            {
                Logger.Warning($"View '{viewTitle}' already exist on list {listTitle}");
                return;
            }

            var newView = l.Views.Add(new ViewCreationInformation
            {
                Title = viewTitle,
                ViewFields = fields
            });

            if (setAdditionalProperties != null)
            {
                setAdditionalProperties(newView);
            }

            newView.Update();
            ctx.ExecuteQuery();
        }
开发者ID:ronnieholm,项目名称:Bugfree.Spo.Cqrs,代码行数:32,代码来源:CreateListView.cs

示例13: Execute

        public void Execute(ClientContext ctx, string listTitle, XElement fieldXml, Action<Field> setAdditionalProperties = null)
        {
            var displayName = fieldXml.Attribute("DisplayName").Value;
            Logger.Verbose($"Started executing {nameof(CreateListColumn)} for column '{displayName}' on list '{listTitle}'");

            var list = ctx.Web.Lists.GetByTitle(listTitle);
            var fields = list.Fields;
            ctx.Load(fields);
            ctx.ExecuteQuery();

            var candidate = fields.SingleOrDefault(f => f.Title == displayName);
            if (candidate != null)
            {
                Logger.Warning($"Column '{displayName}' already on list '{listTitle}'");
                return;
            }

            var newField = fields.AddFieldAsXml(fieldXml.ToString(), true, AddFieldOptions.DefaultValue);
            ctx.Load(newField);
            ctx.ExecuteQuery();

            if (setAdditionalProperties != null)
            {
                setAdditionalProperties(newField);
                newField.Update();
            }
        }
开发者ID:ronnieholm,项目名称:Bugfree.Spo.Cqrs,代码行数:27,代码来源:CreateListColumn.cs

示例14: AddField_Using_FieldSchemaXml

        //Not In Use - AddField_Using_FieldSchemaXml
        public static void AddField_Using_FieldSchemaXml(ClientContext clientContext, List listToBeReplaced, List NewList)
        {
            FieldCollection fields = listToBeReplaced.Fields;
            clientContext.Load(fields);
            clientContext.ExecuteQuery();

            foreach (Field _Fld in fields)
            {
                string _IName = _Fld.InternalName;

                /*Console.WriteLine("InternalName: " + _Fld.InternalName);
                Console.WriteLine("Title: " + _Fld.Title);
                Console.WriteLine("StaticName: " + _Fld.StaticName);
                Console.WriteLine("SchemaXml: " + _Fld.SchemaXml);
                Console.WriteLine("**************************");*/

                if (!Field_ISAlreadyExists(NewList, _IName, clientContext))
                {
                    string _ListColumnNewSchemaXml = Field_UpdateSchemaXml(_Fld, _Fld.InternalName, _Fld.Title);

                    if (_ListColumnNewSchemaXml != null)
                    {
                        Field _Updated_SiteColumnField = NewList.Fields.AddFieldAsXml(_ListColumnNewSchemaXml, true, AddFieldOptions.DefaultValue);
                        clientContext.Load(_Updated_SiteColumnField);
                        clientContext.ExecuteQuery();
                    }
                }
            }
        }
开发者ID:OfficeDev,项目名称:PnP-Transformation,代码行数:30,代码来源:ListMigrationHelper.cs

示例15: InitializeClientContext

    static void InitializeClientContext() {

      // create new client context
      string targetSharePointSite = ConfigurationManager.AppSettings["targetSharePointSite"];
      clientContext = new ClientContext(targetSharePointSite);
      
      // get user name and secure password
      string userName = ConfigurationManager.AppSettings["accessAccountName"];
      string pwd = ConfigurationManager.AppSettings["accessAccountPassword"];
      SecureString spwd = new SecureString();
      foreach (char c in pwd.ToCharArray()) {
        spwd.AppendChar(c);
      }
    
        // create credentials for SharePoint Online using Office 365 user account
      clientContext.Credentials = new SharePointOnlineCredentials(userName, spwd);

      // initlaize static variables for client context, web and site
      siteCollection = clientContext.Site;
      clientContext.Load(siteCollection);
      site = clientContext.Web;
      clientContext.Load(site);
      siteRootFolder = site.RootFolder;
      clientContext.Load(siteRootFolder);
      clientContext.Load(site.Lists);

      TopNavNodes = site.Navigation.TopNavigationBar;
      clientContext.Load(TopNavNodes);
      clientContext.ExecuteQuery();

    }
开发者ID:CriticalPathTraining,项目名称:DSU365,代码行数:31,代码来源:Program.cs


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