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


C# CamlQuery类代码示例

本文整理汇总了C#中CamlQuery的典型用法代码示例。如果您正苦于以下问题:C# CamlQuery类的具体用法?C# CamlQuery怎么用?C# CamlQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetLookupFieldValue

        public static FieldLookupValue GetLookupFieldValue(string lookupName, string lookupListName, ClientContext clientContext)
        {
            //Ref: Karine Bosch - https://karinebosch.wordpress.com/2015/05/11/setting-the-value-of-a-lookup-field-using-csom/
            var lookupList = clientContext.Web.Lists.GetByTitle(lookupListName);
            CamlQuery query = new CamlQuery();
            string lookupFieldName = ConfigurationManager.AppSettings["LookupFieldName"].ToString();
            string lookupFieldType = ConfigurationManager.AppSettings["LookupFieldType"].ToString();

            query.ViewXml = string.Format(@"<View><Query><Where><Eq><FieldRef Name='{0}'/><Value Type='{1}'>{2}</Value></Eq>" +
                                            "</Where></Query></View>", lookupFieldName, lookupFieldType, lookupName);

            ListItemCollection listItems = lookupList.GetItems(query);
            clientContext.Load(listItems, items => items.Include
                                                (listItem => listItem["ID"],
                                                listItem => listItem[lookupFieldName]));
            clientContext.ExecuteQuery();

            if (listItems != null)
            {
                ListItem item = listItems[0];
                FieldLookupValue lookupValue = new FieldLookupValue();
                lookupValue.LookupId = int.Parse(item["ID"].ToString());
                return lookupValue;
            }

            return null;
        }
开发者ID:ALCBerry87,项目名称:SPO-Import-List-CSV,代码行数:27,代码来源:Program.cs

示例2: SearchItemByName

        protected ListItem SearchItemByName(List list, Folder folder, string pageName)
        {
            var context = list.Context;

            if (folder != null)
            {
                if (!folder.IsPropertyAvailable("ServerRelativeUrl"))
                {
                    folder.Context.Load(folder, f => f.ServerRelativeUrl);
                    folder.Context.ExecuteQueryWithTrace();
                }
            }

            var dQuery = new CamlQuery();

            string QueryString = "<View><Query><Where>" +
                             "<Eq>" +
                               "<FieldRef Name=\"FileLeafRef\"/>" +
                                "<Value Type=\"Text\">" + pageName + "</Value>" +
                             "</Eq>" +
                            "</Where></Query></View>";

            dQuery.ViewXml = QueryString;

            if (folder != null)
                dQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;

            var collListItems = list.GetItems(dQuery);

            context.Load(collListItems);
            context.ExecuteQueryWithTrace();

            return collListItems.FirstOrDefault();

        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:35,代码来源:PublishingPageLayoutModelHandler.cs

示例3: GetCustomer

		internal static Customer GetCustomer (this ClientContext ctx, int id) {
			if (ctx.Web.ListExists("Customer") && ctx.Web.ListExists("Order")) {
				//get Customer
				var customers = ctx.Web.Lists.GetByTitle("Customer");
				var cQuery = new CamlQuery();
				cQuery.ViewXml = [email protected]"<View><Query><Where><Eq>
					<FieldRef Name='ID' /><Value Type='Counter'>{id}</Value>
				</Eq></Where></Query></View>";
				var customer = customers.GetItems(cQuery);

				//Get Orders
				var orders = ctx.Web.Lists.GetByTitle("Order");
				var oQuery = new CamlQuery();
				oQuery.ViewXml = [email protected]"<View><Query><Where><Eq>
					<FieldRef Name='Customer' LookupId='TRUE'/><Value Type='Lookup'>{id}</Value>
				</Eq></Where></Query></View>";
				var customerOrders = orders.GetItems(oQuery);

				//Loading
				ctx.Load(customer);
				ctx.Load(customerOrders);

				ctx.ExecuteQuery();
				var ret = customer[0].ParseCustomer();
				ret.Orders = customerOrders.ParseOrders();
				return ret; 
			}
			return null;

		}
开发者ID:Luviz,项目名称:OfficeDev1.MAssinment,代码行数:30,代码来源:Get_Customers.cs

示例4: GetLastSiteCollectionNumber

        /// <summary>
        /// Returns the last used site collection number
        /// </summary>
        /// <param name="siteDirectoryHost">Url to the site directory site collection</param>
        /// <param name="listName">Name of the site directory list</param>
        /// <returns>last used site collection number</returns>
        public int GetLastSiteCollectionNumber(ClientContext cc, Web web, string siteDirectoryHost, string listName)
        {
            int lastNumber = 0;

            List listToInsertQuery = web.Lists.GetByTitle(listName);

            CamlQuery query = new CamlQuery();
            query.ViewXml = "<View>"
               + "<Query>"
               + String.Format("<Where><Eq><FieldRef Name='CreateYear' /><Value Type='Int'>{0}</Value></Eq></Where>", DateTime.Now.ToString("yyyy"))
               + "<OrderBy><FieldRef Name='CreateSeq' Ascending='FALSE'/></OrderBy>"
               + "</Query>"
               + "<RowLimit>1</RowLimit>"
               + "</View>";
            // execute the query
            ListItemCollection listItems = listToInsertQuery.GetItems(query);
            cc.Load(listItems);
            cc.ExecuteQuery();

            if (listItems.Count == 1)
            {
                int.TryParse(listItems[0]["CreateSeq"].ToString(), out lastNumber);
            }

            return lastNumber;
        }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:32,代码来源:SiteDirectoryManager.cs

示例5: Main

        static void Main(string[] args)
        {
            using (var context = new ClientContext(Constants.URL))
            {
                context.Credentials = new SharePointOnlineCredentials(Constants.User, GetPassSecure(Constants.Pass));
                // Assume that the web has a list named "Announcements".
                List twitterList = context.Web.Lists.GetByTitle(Constants.ListTwitter);

                var query= new CamlQuery{
                    ViewXml = @"<View>
                                <Query>
                               <Where><IsNull><FieldRef Name='Sexo' /></IsNull>
                                </Where>
                                </Query>
                                <RowLimit>1</RowLimit>
                                </View>"
                };

               var collection= twitterList.GetItems(query);
                context.Load(collection);
                context.ExecuteQuery();

                foreach(var item in collection)
                {
                   Function.DetecFacesAndDisplayResult(item["Foto"].ToString(),item.Id.ToString());

                }

                Console.ReadLine();
                Console.WriteLine("Actualizado");

            }
        }
开发者ID:AdrianDiaz81,项目名称:Gapand,代码行数:33,代码来源:Program.cs

示例6: Index

        public ActionResult Index(string category = "") {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

            using (var clientContext = HttpContext.GetUserClientContextForSPHost()) {
                ViewBag.SPHostUrl = spContext.SPHostUrl;
                ViewBag.Category = category;

                var list = clientContext.Web.GetListByTitle(ListDetails.EventsListName);
                var categoryQuery = string.Empty;
                if (!string.IsNullOrEmpty(category)) {
                    categoryQuery = CAML.Where(CAML.Eq(CAML.FieldValue(Event.FIELD_CATEGORY, "Text", category)));
                }
                var orderByQuery = CAML.OrderBy(new OrderByField("Title"));

                var caml = new CamlQuery() {
                    ViewXml = CAML.ViewQuery(categoryQuery, orderByQuery, rowLimit: 50)
                };
                var events = list.GetItems(caml);
                clientContext.Load(events);
                clientContext.ExecuteQuery();

                var eventsList = events.Cast<ListItem>().Select(item => new Event(item)).ToList();
                return View(eventsList);
            }
        } 
开发者ID:Calisto1980,项目名称:PnP,代码行数:25,代码来源:EventsController.cs

示例7: btnSearch_Click

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            SPQuery qry = new SPQuery();
            SPWeb rootWeb = Site.RootWeb;
            SPList list = rootWeb.Lists["Articles"];
            CamlQuery caml = new CamlQuery();
            SPQuery articleQuery = new SPQuery();
            articleQuery.Query = CAML.Where(
                                CAML.Contains(
                                    CAML.FieldRef("Title"),
                                    CAML.Value(txtTitleSearch.Text)));

            //articleQuery.ViewFields = CAML.ViewFields(CAML.FieldRef("Title"), CAML.FieldRef("Modified By"));
            //articleQuery.ViewFields = string.Concat(
            //                    "<FieldRef Name='Title' />",
            //                   "<FieldRef Name='Modified' />");

            //articleQuery.ViewFieldsOnly = true;
            //articleQuery.ViewFields = "<ViewFields><FieldRef Name=\"Title\"/></ViewFields>";

            SPListItemCollection col;

            if (txtTitleSearch.Text.Length == 0)
            {
                col = list.Items;
            }
            else
            {
                col = list.GetItems(articleQuery);
            }

            ViewState["AtricleSearchResults"] = col.GetDataTable();
            gvResult.DataSource = col.GetDataTable();
            gvResult.DataBind();
        }
开发者ID:MohitVash,项目名称:TestProject,代码行数:35,代码来源:ArticleSelectDialog.aspx.cs

示例8: ConnectStore

        private void ConnectStore(int listitemid, int groupid) {
            List listConnect = _ctx.Web.Lists.GetByTitle("Grupper för försäljningsställen");
            CamlQuery cq = new CamlQuery();

            cq.ViewXml = @"<View>  
        <Query> 
            <Where><Eq><FieldRef Name='F_x00f6_rs_x00e4_ljningsst_x00e4' LookupId='True' /><Value Type='Lookup'>" + listitemid.ToString() + @"</Value></Eq></Where> 
        </Query> 
    </View>";
            ListItemCollection items = listConnect.GetItems(cq);
            _ctx.Load(items);
            _ctx.ExecuteQuery();
            if (items.Count == 0) {
                ListItem item = listConnect.AddItem(new ListItemCreationInformation { });
                item["F_x00f6_rs_x00e4_ljningsst_x00e4"] = listitemid;
                item["Grupp"] = groupid;
                item.Update();
            }
            else {
                foreach (ListItem item in items) {
                    item["Grupp"] = groupid;
                    item.Update();
                }
            }

        }
开发者ID:Jerntorget,项目名称:UPCOR.W.SetRights,代码行数:26,代码来源:Form1.cs

示例9: Main

        static void Main(string[] args)
        {
            Uri siteUri = new Uri(ConfigurationManager.AppSettings["SiteCollectionRequests_SiteUrl"]);

            //Get the realm for the URL
            string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);

            //Get the access token for the URL.
            //   Requires this app to be registered with the tenant
            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal,
                siteUri.Authority, realm).AccessToken;

            //Get client context with access token
            using (var ctx =
                TokenHelper.GetClientContextWithAccessToken(
                    siteUri.ToString(), accessToken))
            {
                // Get items which are in requested status
                List list = ctx.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["SiteCollectionRequests_List"]);
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Status'/>" +
                                    "<Value Type='Text'>Requested</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>";
                ListItemCollection listItems = list.GetItems(camlQuery);
                ctx.Load(listItems);
                ctx.ExecuteQuery();

                foreach (ListItem item in listItems)
                {
                    // get item one more time and check that it's still in requested status
                    ListItem listItem = list.GetItemById(item.Id);
                    ctx.Load(listItem);
                    ctx.ExecuteQuery();

                    if (listItem["Status"].ToString().ToLowerInvariant() == "Requested".ToLowerInvariant())
                    {
                        try
                        {
                            // Mark it as provisioning
                            UpdateStatusToList(ctx, listItem.Id, "Provisioning", "Started provisioning at " + DateTime.Now.ToString());

                            // Process request
                            string newUrl = ProcessSiteCreationRequest(ctx, listItem);

                            // Mark it as provisioning
                            UpdateStatusToList(ctx, listItem.Id, "Ready", "Created at " + DateTime.Now.ToString());

                            // Send email
                            SendEmailToRequestorAndNotifiedEmail(ctx, listItem, newUrl);

                        }
                        catch (Exception ex)
                        {
                            // Store the exception information to the list for viewing from browser
                            UpdateStatusToList(ctx, listItem.Id, "Failed", ex.Message);
                        }
                    }
                }
            }
        }
开发者ID:nitewolfgtr,项目名称:PnP,代码行数:60,代码来源:Program.cs

示例10: GetAll

        public IEnumerable<Person> GetAll()
        {
            var spContext = SharePointContext.GetClientContext();

            var spList = spContext.Web.Lists.GetByTitle("Person");
            spContext.Load(spList);
            spContext.ExecuteQuery();
            if (spList == null || spList.ItemCount <= 0) return null;
            var camlQuery = new CamlQuery
            {
                ViewXml = @"<View>
                                <RowLimit>20</RowLimit>
                             </View>",
                DatesInUtc = true
            };
            var listItems = spList.GetItems(camlQuery);
            spContext.Load(listItems);
            spContext.ExecuteQuery();
            var resultItems = new List<Person>();

            foreach (var item in listItems)
            {
                var personItem = new Person
                {
                    Id = item.Id,
                    Name = item["Name"].ToString(),
                    LastName = item["LastName"].ToString()
                };
                resultItems.Add(personItem);
            }

            return resultItems;
        }
开发者ID:angelrubenyui,项目名称:workshops2015,代码行数:33,代码来源:PersonService.cs

示例11: Main

 static void Main(string[] args)
 {
     ClientContext context = new ClientContext("http://sp.weiyun.com/sites/Doc");
     context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
     FormsAuthenticationLoginInfo formsAuthinfo = new FormsAuthenticationLoginInfo("DEL00001", "1234!qwer");
     context.FormsAuthenticationLoginInfo = formsAuthinfo;
     //context.Credentials = new NetworkCredential("DEL00001", "1234!qwer");
     Web web = context.Web;
     List list = web.Lists.GetByTitle("DocLib");
     CamlQuery camlQuery = new CamlQuery();
     camlQuery.ViewXml =
         @"<View>
             <Query>
                 <Where>
                     <Eq>
                         <FieldRef Name = 'Title' />
                         <Value Type='Text'>71342245-c3c8-4094-a555-842a6763b201_081464afff6f457eac23e2168c82a974</Value>
                     </Eq>
                 </Where>
             </Query>
         </View>";
     ListItemCollection items = list.GetItems(camlQuery);
     //context.Load(web,w=>w.Title,w=>w.Description);
     context.Load(items, s => s.Include(item => item["Title"]));
     //context.LoadQuery
     context.ExecuteQuery();
     //string Title = web.Title;
    //Console.WriteLine(string.Format("Web Title is {0}, Descript is {1}!",Title,web.Description));
     int i = items.Count;
     foreach (ListItem item in items)
     {
         Console.WriteLine("Title:{0}",item["Title"]);
     }
 }
开发者ID:SPRED,项目名称:SPRED,代码行数:34,代码来源:Program.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {

            string siteUrl = "https://hp-27b0ee14ded081.sharepoint.com/teams/spohub/ACSMigrationManager/";

            ClientContext clientContext = new ClientContext(siteUrl);
            System.Security.SecureString pwd = new System.Security.SecureString();
            pwd.AppendChar('p');
            pwd.AppendChar('a');
            pwd.AppendChar('s');
            pwd.AppendChar('s');
            pwd.AppendChar('@');
            pwd.AppendChar('w');
            pwd.AppendChar('o');
            pwd.AppendChar('r');
            pwd.AppendChar('d');
            pwd.AppendChar('1');
            clientContext.Credentials = new SharePointOnlineCredentials("[email protected]", pwd);
            Web site = clientContext.Web;
            clientContext.Load(site);
            clientContext.ExecuteQuery();

            SP.List oList = clientContext.Web.Lists.GetByTitle("Migration Tasks");
            CamlQuery query;
            string sitesText = "" + textBox1.Text;
            sitesText = sitesText.Replace("\r", "");
            sitesText = sitesText.Replace("\n", ",");
            string[] sites = null;
            if (sitesText.Length > 0)
            {
                sites = sitesText.Split(',');

                for (int i = 0; i < sites.Length; i++)
                {
                    if (sites[i].Trim().Length > 0)
                    {
                        query = new CamlQuery();
                        query.ViewXml = "<View><Query><Where><Contains><FieldRef Name='ContentSource'/><Value Type='Text'>" +
                            sites[i] + "</Value></Contains></Where></Query></View>";
                        ListItemCollection collListItem = oList.GetItems(query);

                        clientContext.Load(collListItem);
                        clientContext.ExecuteQuery();



                        if (collListItem.Count == 1)
                        {
                            ListItem oListItem = collListItem[0];
                            //listBox1.DataSource = collListItem;
                            textBox3.Text += oListItem["Title"].ToString() + @"
";
                            oListItem["MigrationStatus"] = textBox2.Text;
                            oListItem.Update();
                            clientContext.ExecuteQuery();
                        }
                    }
                }
            }
        }
开发者ID:bassemfg,项目名称:Sites-status-updater,代码行数:60,代码来源:Form1.cs

示例13: GetItems

        public IEnumerable<Item> GetItems()
        {
            using (var clientContext = WebAPIHelper.GetClientContext(ControllerContext))
            { 
                if (clientContext != null)
                {
                    List demoList = clientContext.Web.Lists.GetByTitle("WebAPIDemo");
                    CamlQuery camlQuery = new CamlQuery();
                    camlQuery.ViewXml = "<View><Query></Query></View>";
                    ListItemCollection demoItems = demoList.GetItems(camlQuery);
                    clientContext.Load(demoItems);
                    clientContext.ExecuteQuery();  
                    
                    Item[] items = new Item[demoItems.Count];

                    int i=0;
                    foreach (ListItem item in demoItems)
                    {
                        items[i] = new Item() { Id = item.Id, Title = item["Title"].ToString() };
                        i++;
                    }

                    return items;
                }
                else
                {
                    return new Item[0];
                }
            }
        }
开发者ID:tandis,项目名称:PnP,代码行数:30,代码来源:DemoController.cs

示例14: Get

        public Publications Get(int id)
        {
            var list = context.Web.Lists.GetByTitle(Title);
            var query = new CamlQuery() { ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + id + "</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>" };
            var items = list.GetItems(query);
            context.Load(items);
            context.ExecuteQuery();

            if (items.Count > 0)
            {
                string[] lines = items[0]["_x0422__x044d__x0433__x0438_"].ToString().Split(',');

                var tags = new List<Tag>();

                foreach (var line in lines)
                {
                    tags.Add(mapTag(line));
                }

                return new Publications()
                {
                    Title = items[0]["Title"].ToString(),
                    Article = items[0]["_x0421__x0442__x0430__x0442__x04"].ToString(),
                    PublicationDate = ((DateTime)items[0]["_x0414__x0430__x0442__x0430__x00"]).AddDays(1),
                    Source = items[0]["_x0418__x0441__x0442__x043e__x04"].ToString(),
                    Subtitle = items[0]["_x041f__x043e__x0434__x0437__x04"].ToString(),
                    Tags = tags
                };
            }
            else
            {
                return null;
            }
        }
开发者ID:ellestragoo,项目名称:new-cft,代码行数:34,代码来源:PublicationsRepository.cs

示例15: ThemeEntryExists

        private bool ThemeEntryExists(Web web, List themeList, string themeName)
        {

            CamlQuery query = new CamlQuery();
            string camlString = @"
                <View>
                    <Query>                
                        <Where>
                            <Eq>
                                <FieldRef Name='Name' />
                                <Value Type='Text'>{0}</Value>
                            </Eq>
                        </Where>
                     </Query>
                </View>";
            // Let's update the theme name accordingly
            camlString = string.Format(camlString, themeName);
            query.ViewXml = camlString;
            var found = themeList.GetItems(query);
            web.Context.Load(found);
            web.Context.ExecuteQuery();
            if (found.Count > 0)
            {
                return true;
            }
            return false;
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:27,代码来源:ThemeManager.cs


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