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


C# ClientContext.ExecuteQueryAsync方法代码示例

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


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

示例1: GetReasonlist

        public void GetReasonlist(string listName, Action<List<string>> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ClientContext _ctx = new ClientContext(_siteUrl);
            ListItemCollection listItems = _ctx.Web.Lists.GetByTitle(listName).GetItems(new CamlQuery());
            _ctx.Load(listItems);
            
            SuccessHandler = (s, e) =>
            {
                List<ListItem> items = listItems.ToList();
                List<string> reasonList = new List<string>();
                string title;
                foreach (ListItem item in items)
                {
                    title = GetPropertyValue(item.FieldValues["Title"], "Title");
                    reasonList.Add(title);
                }

                reply(reasonList);
            };
            FailureHandler = (s, e) =>
            {
                reply(null);
            };
            _ctx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:28,代码来源:LateIncompleteReason.cs

示例2: GetBusinessUnits

        public void GetBusinessUnits(string listName, Action<List<BusinessUnit>,Exception> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ClientContext _ctx = new ClientContext(_siteURL);
            ListItemCollection  listItems = _ctx.Web.Lists.GetByTitle(listName).GetItems(new CamlQuery());            
            _ctx.Load(listItems);

            SuccessHandler = (s, e) =>
            {
                List<ListItem> items = listItems.ToList();
                List<BusinessUnit> businessUnits = new List<BusinessUnit>();
                foreach (ListItem item in items)
                {
                    var newBusinessUnit = new BusinessUnit(){
                        Title = GetPropertyValue(item.FieldValues[BusinessUnit.Columns.Title], BusinessUnit.Columns.Title),
                        Map = GetPropertyValue(item.FieldValues[BusinessUnit.Columns.Map], BusinessUnit.Columns.Map),
                        LinkToMandatory = bool.Parse(GetPropertyValue(item.FieldValues[BusinessUnit.Columns.LinkToMandatory], BusinessUnit.Columns.LinkToMandatory))
                    };
                    businessUnits.Add(newBusinessUnit);
                }
                reply(businessUnits, null);
            };

            FailureHandler = (s, e) =>
            {
                Logger.AddLog(_log, e.Exception);
                reply(null, e.Exception);
            };

            _ctx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:33,代码来源:BusinessUnitServiceAgent.cs

示例3: GetListItemsClientObjectModel

        private void GetListItemsClientObjectModel()
        {
            _clientContext = new ClientContext("http://jakesharepointsaturday.sharepoint.com/TeamSite");

            Web site = _clientContext.Web;
            _list = site.Lists.GetByTitle("Death Star Inventory 2");

            _items = _list.GetItems(new CamlQuery());
            //_clientContext.Load(_items);
            _clientContext.Load(_items, items => items.Include(i => i["Item_x0020_Type"], i => i["Fire_x0020_Power"], i => i["Title"]));

            _clientContext.ExecuteQueryAsync(SuccessCallback, FailedCallback);
        }
开发者ID:bkama,项目名称:presentations,代码行数:13,代码来源:MainPage.xaml.cs

示例4: MainPage

        public MainPage()
        {
            InitializeComponent();

            _clientContext = new ClientContext("http://jakesharepointsaturday.sharepoint.com/TeamSite");

            Web site = _clientContext.Web;
            _list = site.Lists.GetByTitle("Important Documents");

            _items = _list.GetItems(new CamlQuery());
            _clientContext.Load(_items);
            _clientContext.ExecuteQueryAsync(SuccessCallback, FailedCallback);
        }
开发者ID:bkama,项目名称:presentations,代码行数:13,代码来源:MainPage.xaml.cs

示例5: LoadResults

        public async void LoadResults(string siteUrl, string keywords, string login, string mdp)
        {
            ObservableCollection<CortanaItem> cortanaResults = new ObservableCollection<CortanaItem>();

            keywords = keywords.Trim('.').ToLower();

            try
            {
                using (ClientContext context = new ClientContext(siteUrl))
                {
                    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(login, mdp);
                    context.Credentials = credentials;

                    KeywordQuery keywordQuery = new KeywordQuery(context);
                    keywordQuery.QueryText = keywords;
                    keywordQuery.SourceId = new Guid(SettingsValues.SourceId);
                    keywordQuery.EnablePhonetic = true;
                    keywordQuery.EnableStemming = true;
                    keywordQuery.RowLimit = 100;

                    SearchExecutor searchExecutor = new SearchExecutor(context);

                    ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);

                    context.ExecuteQueryAsync().Wait();

                    foreach (var item in results.Value[0].ResultRows)
                    {
                        CortanaItem ci = new CortanaItem();
                        ci.Id = item["ID"] != null ? item["ID"].ToString() : string.Empty;
                        ci.Title = item["Title"] != null ? item["Title"].ToString() : string.Empty;
                        ci.LastModifiedDate = item["Modified"] != null ? item["Modified"].ToString() : string.Empty;
                        ci.Url = item["Path"] != null ? item["Path"].ToString() : string.Empty;
                        cortanaResults.Add(ci);
                    }
                }

                LoadDataCompleted(cortanaResults); // Fire event DataLoadCompleted

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Erreur : " + ex.Message);
                LoadDataCompleted(null);
            }
        }
开发者ID:Mohye77,项目名称:CortanaSharePoint,代码行数:46,代码来源:CortanaSearchRequester.cs

示例6: MainPage

        public MainPage()
        {
            InitializeComponent();

            ClientContext context = new ClientContext(ApplicationContext.Current.Url);
            context.Load(context.Web);
            List employees = context.Web.Lists.GetByTitle("Employees");
            context.Load(employees);

            CamlQuery query = new CamlQuery();
            string camlQueryXml = null;

            query.ViewXml = camlQueryXml;
            _employees = employees.GetItems(query);
            context.Load(_employees);
            context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);
        }
开发者ID:sreekanth642,项目名称:sp2010_lab,代码行数:17,代码来源:MainPage.xaml.cs

示例7: LayoutRoot_Drop

        private void LayoutRoot_Drop(object sender, DragEventArgs e)
        {
            message.Text = "Item Dropped!";
            FileInfo[] droppedFiles = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];

            ClientContext clientContext = new ClientContext("http://jakesharepointsaturday.sharepoint.com/TeamSite");
            _site = clientContext.Web;
            _list = _site.Lists.GetByTitle("Important Documents");

            foreach (FileInfo file in droppedFiles)
            {
                byte[] contents  = GetContentsOfFile(file);

                FileCreationInformation newFile = new FileCreationInformation();
                newFile.Content = contents;
                newFile.Url = file.Name;

                Microsoft.SharePoint.Client.File uploadFile = _list.RootFolder.Files.Add(newFile);
                clientContext.Load(uploadFile);
                clientContext.ExecuteQueryAsync(SuccessCallback, FailedCallback);
            }
        }
开发者ID:bkama,项目名称:presentations,代码行数:22,代码来源:MainPage.xaml.cs

示例8: MainPage

        public MainPage()
        {
            InitializeComponent();

            ClientContext context = new ClientContext(ApplicationContext.Current.Url);
            context.Load(context.Web);
            List Projects = context.Web.Lists.GetByTitle("Projects");
            context.Load(Projects);

            CamlQuery query = new Microsoft.SharePoint.Client.CamlQuery();
            string camlQueryXml = "<View><Query><Where><Gt>" +
                "<FieldRef Name='Due_x0020_Date' />" +
                "<Value Type='DateTime'>2008-01-1T00:00:00Z</Value>" +
                "</Gt></Where></Query><ViewFields>" +
                "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" />" +
                "<FieldRef Name=\"Due_x0020_Date\" />" +
                "</ViewFields></View>";

            query.ViewXml = camlQueryXml;
            _projects = Projects.GetItems(query);
            context.Load(_projects);
            context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), null);
        }
开发者ID:sreekanth642,项目名称:sp2010_lab,代码行数:23,代码来源:MainPage.xaml.cs

示例9: LoadItems

        public async void LoadItems(string siteUrl, string listName, string login, string mdp)
        {
            ObservableCollection<CortanaItem> cortanaItems = new ObservableCollection<CortanaItem>();

            try
            {
                using (ClientContext context = new ClientContext(siteUrl))
                {
                    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(login, mdp);
                    context.Credentials = credentials;
                    Web web = context.Web;
                    ListItemCollection listItemCollection = web.Lists.GetByTitle(listName).GetItems(CamlQuery.CreateAllItemsQuery());
                    context.Load(listItemCollection);

                    await context.ExecuteQueryAsync().ContinueWith((t) =>
                    {
                        foreach (var item in listItemCollection)
                        {
                            CortanaItem ci = new CortanaItem();
                            ci.Id = item.FieldValues["ID"] != null ? item.FieldValues["ID"].ToString() : string.Empty;
                            ci.Title = item.FieldValues["Title"] != null ? item.FieldValues["Title"].ToString() : string.Empty;
                            ci.LastModifiedDate = item.FieldValues["Modified"] != null ? item.FieldValues["Modified"].ToString() : string.Empty;
                            ci.Url = item.FieldValues["FileRef"] != null ? item.FieldValues["FileRef"].ToString() : string.Empty;
                            cortanaItems.Add(ci);
                        }
                    });
                }

                LoadDataCompleted(cortanaItems); // Fire event DataLoadCompleted

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Erreur : " + ex.Message);
                LoadDataCompleted(null);
            }
        }
开发者ID:Mohye77,项目名称:CortanaSharePoint,代码行数:37,代码来源:CortanaItemsRequester.cs

示例10: MainViewModel

        public MainViewModel(Dispatcher dispatcher)
        {
            _dispatcher = dispatcher;

            Search = new RelayCommand(SearchHandler);

            ClientContext clientContext = new ClientContext("http://jakesharepointsaturday.sharepoint.com/TeamSite");
            _site = clientContext.Web;
            _personnelList = _site.Lists.GetByTitle("Personnel");
            _personnel = _personnelList.GetItems(new CamlQuery());
            //_items.Include(item => item["Title"], item => item["First_x0020_Name"], item => item["Last_x0020_Name"], item => item["Fun_x0020_Fact"], item => item["Office"], item => item["PersonnelTitle"], item => item["Image"]);
            clientContext.Load(_personnel);
            //clientContext.ExecuteQueryAsync(SuccessCallback, FailedCallback);

            List officeList = _site.Lists.GetByTitle("Office");
            _officeSPItems = officeList.GetItems(new CamlQuery());
            clientContext.Load(_officeSPItems);

            List titleList = _site.Lists.GetByTitle("Titles");
            _titlesSPItems = titleList.GetItems(new CamlQuery());
            clientContext.Load(_titlesSPItems);

            clientContext.ExecuteQueryAsync(SuccessCallback, FailedCallback);
        }
开发者ID:bkama,项目名称:presentations,代码行数:24,代码来源:MainViewModel.cs

示例11: LoadAppointments

        public async void LoadAppointments(string siteUrl, string calendarName, string login, string mdp)
        {
            ObservableCollection<CortanaAppointment> cortanaAppointments = new ObservableCollection<CortanaAppointment>();

            try
            {
                using (ClientContext context = new ClientContext(siteUrl))
                {
                    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(login, mdp);
                    context.Credentials = credentials;
                    Web web = context.Web;
                    ListItemCollection calendarAppointmentsCollection = web.Lists.GetByTitle(calendarName).GetItems(CamlQuery.CreateAllItemsQuery());
                    context.Load(calendarAppointmentsCollection);

                    await context.ExecuteQueryAsync().ContinueWith((t) =>
                    {
                        foreach (var item in calendarAppointmentsCollection)
                        {
                            CortanaAppointment ci = new CortanaAppointment();
                            ci.Id = item.FieldValues["ID"] != null ? item.FieldValues["ID"].ToString() : string.Empty;
                            ci.Subject = item.FieldValues["Title"] != null ? item.FieldValues["Title"].ToString() : string.Empty;
                            ci.StartDate = item.FieldValues["EventDate"] != null ? DateTime.Parse(item.FieldValues["EventDate"].ToString()) : new DateTime();
                            cortanaAppointments.Add(ci);
                        }
                    });
                }

                LoadDataCompleted(cortanaAppointments); // Fire event DataLoadCompleted

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Erreur : " + ex.Message);
                LoadDataCompleted(null);
            }
        }
开发者ID:Mohye77,项目名称:CortanaSharePoint,代码行数:36,代码来源:CortanaAppointmentsRequester.cs

示例12: GetSystemOutragelist

        public void GetSystemOutragelist(string listName, Action<List<SystemOutrageLookUp>> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ClientContext _ctx = new ClientContext(_siteUrl);

            CamlQuery qry = new CamlQuery();
            qry.ViewXml = @"<View>                              
                              <ViewFields>
                                <FieldRef Name='Title' />
                                <FieldRef Name='ReasonListTitle' />                                
                              </ViewFields>
                              <ProjectedFields>                               
                                <Field Name='ReasonListTitle' Type='Lookup' 
                                       List='ReasonList' ShowField='Title' />                             
                              </ProjectedFields>
                              <Joins>
                                <Join Type='LEFT' ListAlias='ReasonList'>                                
                                  <Eq>
                                    <FieldRef Name='Reason' RefType='Id' />
                                    <FieldRef List='ReasonList' Name='ID' />
                                  </Eq>
                                </Join>
                              </Joins>
                            </View>";
           
            ListItemCollection listItems = _ctx.Web.Lists.GetByTitle(listName).GetItems(qry);
            _ctx.Load(listItems);

            SuccessHandler = (s, e) =>
            {
                List<ListItem> items = listItems.ToList();
                List<SystemOutrageLookUp> reasonSystemList = new List<SystemOutrageLookUp>();
             
                foreach (ListItem item in items)
                {
                    var newItem = new SystemOutrageLookUp(){
                        ReasonTitle =  GetPropertyValue(item.FieldValues["ReasonListTitle"],"ReasonListTitle"),
                        SystemOutrageTitle = GetPropertyValue(item.FieldValues["Title"], "Title")
                    };
                    reasonSystemList.Add(newItem);
                }
                reply(reasonSystemList);
            };
            FailureHandler = (s, e) =>
            {
                reply(null);
            };
            _ctx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:51,代码来源:LateIncompleteReason.cs

示例13: IntegrityCheckOrganizationStructure

        public void IntegrityCheckOrganizationStructure(OrgStructureEntityModel Org, string listName, string subSiteUrl, Action<bool, Exception> reply)
        {
            const string BUSINESS_AREA_COLUMN = "Business_x0020_Area";
            const string ASSET_CATEGORY_COLUMN = "Asset_x0020_Category";

            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            CamlQuery query = new CamlQuery();
            ClientContext _ctx;
            string field = string.Empty;

            if (Org.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory ||
                Org.LevelName == OrgStructureEntityModel.LevelNames.BusinessArea)
            {
                if (Org.LevelName == OrgStructureEntityModel.LevelNames.AssetCategory)
                    field = ASSET_CATEGORY_COLUMN;
                else if (Org.LevelName == OrgStructureEntityModel.LevelNames.BusinessArea)
                    field = BUSINESS_AREA_COLUMN;
                else
                    field = "";

                query.ViewXml = BuildQuery(field, Org.OriginalTitle);
                _ctx = new ClientContext(subSiteUrl);

                ListItemCollection orgList = _ctx.Web.Lists.GetByTitle(listName).GetItems(query);
                _ctx.Load(orgList);

                SuccessHandler = (s, e) =>
                {
                    if (orgList != null && orgList.Count > 0)
                    {
                        Org.Title = Org.OriginalTitle;
                        reply(false, null);
                    }
                    else
                    {
                        reply(true, null);
                    }
                };

                FailureHandler = (s, e) =>
                {
                    Logger.AddLog(_log, e.Exception);
                    reply(false, e.Exception);
                };

                _ctx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
            }
            else
                reply(true, null);

        }      
开发者ID:nilavghosh,项目名称:VChk,代码行数:53,代码来源:OrgStructureServiceAgent.cs

示例14: AddExistingGroupToSite

        public void AddExistingGroupToSite(int groupId,string subSiteUrl,Action<bool, Exception> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ClientContext ictx = new ClientContext(subSiteUrl);
            Group group = ictx.Site.RootWeb.SiteGroups.GetById(groupId);

            ictx.Load(group,g=>g.Description,g=>g.Id,g=>g.LoginName,g=>g.OwnerTitle,g=>g.Owner.LoginName);
            RoleDefinitionBindingCollection rbc = new RoleDefinitionBindingCollection(ictx);
            RoleDefinition rd = ictx.Web.RoleDefinitions.GetByName("View Only");
            rbc.Add(rd);

            ictx.Web.RoleAssignments.Add(group, rbc);     
            
            SuccessHandler = (s, e) =>
            {              
                reply(true, null);
            };

            FailureHandler = (s, e) =>
            {
                Logger.AddLog(_log, e.Exception);
                reply(false, e.Exception);
            };

            ictx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:28,代码来源:UserGroupServiceAgent.cs

示例15: GetListPermissionsForPrincipal

        public void GetListPermissionsForPrincipal(int groupId, string siteUrl, Action<List<Data.GroupPermission>, Exception> reply)
        {
            ClientRequestSucceededEventHandler SuccessHandler = null;
            ClientRequestFailedEventHandler FailureHandler = null;

            ClientContext ictx = new ClientContext(siteUrl);

            Web website = ictx.Web;
            IEnumerable<List> lists = null;
            
            lists = ictx.LoadQuery(website.Lists.Include(                              
                             lst => lst.Title,
                             lst => lst.RoleAssignments.Include(
                              rm => rm.Member.Id,
                              rm => rm.Member.LoginName,
                              rm => rm.RoleDefinitionBindings.Include(
                              rd => rd.Description,
                              rd => rd.Hidden,
                              rd => rd.Id,
                              rd => rd.Name,
                              rd => rd.RoleTypeKind)
                              ).Where(r => r.Member.Id == groupId)));


            SuccessHandler = (s, e) =>
            {                
                List<Data.GroupPermission> listPermissions = new List<Data.GroupPermission>();
                foreach (List lst in lists)
                {
                    SecurableObject curlst = lst as SecurableObject;
                    if (curlst.RoleAssignments != null && curlst.RoleAssignments.Count > 0)
                    {                
                        Data.GroupPermission pl = new Data.GroupPermission();
                        pl.Name = lst.Title;                        
                        foreach (RoleAssignment r in curlst.RoleAssignments)
                        {
                            foreach (RoleDefinition rd in r.RoleDefinitionBindings)
                            {
                                pl.Permissions.Add(new PermissionLevel()
                                {
                                    Description = rd.Description,
                                    LevelName = rd.Name,
                                    Mask = rd.Id,
                                    IsLevelEnabled = !rd.Hidden,
                                    IsEditable = !rd.Hidden
                                });
                            }
                        }
                        listPermissions.Add(pl);                        
                    }                        
                }
                reply(listPermissions, null);
            };

            FailureHandler = (s, e) =>
            {
                Logger.AddLog(_log, e.Exception);
                reply(null, e.Exception);
            };

            ictx.ExecuteQueryAsync(SuccessHandler, FailureHandler);
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:62,代码来源:UserGroupServiceAgent.cs


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