Esempio n. 1
0
 private void InitializeDocumentLibraryList(Dictionary <Guid, List> documentLibraries)
 {
     using (ClientContext clientContext = new ClientContext(this.siteUri.AbsoluteUri))
     {
         clientContext.Credentials = this.credential;
         if (this.isOAuthCredential)
         {
             clientContext.FormDigestHandlingEnabled = false;
             clientContext.ExecutingWebRequest      += delegate(object sender, WebRequestEventArgs args)
             {
                 args.WebRequestExecutor.RequestHeaders.Add(HttpRequestHeader.Authorization, "Bearer");
                 args.WebRequestExecutor.RequestHeaders.Add("client-request-id", Guid.NewGuid().ToString());
                 args.WebRequestExecutor.RequestHeaders.Add("return-client-request-id", "true");
                 args.WebRequestExecutor.WebRequest.PreAuthenticate = true;
                 args.WebRequestExecutor.WebRequest.UserAgent       = Utils.GetUserAgentStringForSiteMailboxRequests();
             };
         }
         if (this.enableHttpDebugProxy)
         {
             clientContext.ExecutingWebRequest += delegate(object sender, WebRequestEventArgs args)
             {
                 args.WebRequestExecutor.WebRequest.Proxy = new WebProxy("127.0.0.1", 8888);
             };
         }
         clientContext.Load <ListCollection>(clientContext.Web.Lists, new Expression <Func <ListCollection, object> >[]
         {
             (ListCollection items) => ClientObjectQueryableExtension.Include <List>(items, new Expression <Func <List, object> >[]
             {
                 (List item) => (object)item.Id,
                 (List item) => (object)item.BaseType,
                 (List item) => (object)item.OnQuickLaunch,
                 (List item) => item.Title,
                 (List item) => item.RootFolder
             })
         });
         clientContext.ExecuteQuery();
         foreach (List list in clientContext.Web.Lists)
         {
             if (list.BaseType == 1 && list.OnQuickLaunch)
             {
                 documentLibraries.Add(list.Id, list);
             }
         }
     }
 }
        /// <summary>
        /// Retrieving SharePoint list collection
        /// </summary>
        /// <returns> SharePoint list collection</returns>
        public async Task <Generic.List <List> > GetLists()
        {
            Generic.List <List> resultLists = new Generic.List <List>();
            IQueryable <List>   listsWithIncludedProperty = ClientObjectQueryableExtension.Include(context.Web.Lists,
                                                                                                   list => list.Id,
                                                                                                   list => list.Title,
                                                                                                   list => list.ItemCount,
                                                                                                   list => list.Fields.Include(f => f.Title, f => f.Indexed, f => f.InternalName));

            IQueryable <List> listCollection =
                listsWithIncludedProperty.Where(list => list.BaseType == BaseType.DocumentLibrary &&
                                                (list.BaseTemplate == (int)ListTemplateType.DocumentLibrary ||
                                                 list.BaseTemplate == (int)ListTemplateType.MySiteDocumentLibrary) &&
                                                list.Hidden == false);

            Generic.IEnumerable <List> lists = context.LoadQuery(listCollection);
            await ExecuteQuery();

            lists.ForEach(list => resultLists.Add(list));
            return(resultLists);
        }