Exemplo n.º 1
0
        public void UpdateField(string itemId, string fieldName, string value)
        {
            using (var clientContext = new SharePointAdalClientContext(_contextUrl))
            {
                var itemCreateInfo = new ListItemCreationInformation();
                var list           = clientContext.Web.Lists.GetByTitle(_listName);


                var listItem = list.GetItemById(itemId);

                listItem[fieldName] = value;
                listItem.Update();
                clientContext.ExecuteQuery();
            }
        }
Exemplo n.º 2
0
        public void AddItem(Dictionary <string, string> fieldValues)
        {
            using (var clientContext = new SharePointAdalClientContext(_contextUrl))
            {
                var itemCreateInfo = new ListItemCreationInformation();
                var list           = clientContext.Web.Lists.GetByTitle(_listName);

                var listItem = list.AddItem(itemCreateInfo);
                foreach (var v in fieldValues)
                {
                    listItem[v.Key] = v.Value;
                }
                listItem.Update();
                clientContext.ExecuteQuery();
            }
        }
Exemplo n.º 3
0
        public ISharePointListItem GetListItemByLookupField(string fieldName, string value)
        {
            using (var clientContext = new SharePointAdalClientContext(_contextUrl))
            {
                var test = "<View><Query><Where><Eq><FieldRef Name='" + fieldName + "' /><Value Type='Lookup'>" + value +
                           "</Value></Eq></Where></Query></View>";
                var query = new CamlQuery
                {
                    ViewXml = test
                };
                var list   = clientContext.Web.Lists.GetByTitle(_listName);
                var sitems = list.GetItems(query);
                clientContext.Load(sitems, i => i.IncludeWithDefaultProperties(item => item.Id, item => item["Title"]));
                clientContext.ExecuteQuery();

                return(sitems.Count == 1 ? new SharePointListItem(sitems[0]) : null);
            }
        }
Exemplo n.º 4
0
 public ISharePointListItem GetListItemByTitle(string title)
 {
     using (var clientContext = new SharePointAdalClientContext(_contextUrl))
     {
         var test = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + title +
                    "</Value></Eq></Where></Query></View>";
         // string.Format(Constants.SharePointQueries.GetItemByTitleQuery, title);
         var query = new CamlQuery
         {
             ViewXml = test
         };
         var list   = clientContext.Web.Lists.GetByTitle(_listName);
         var sitems = list.GetItems(query);
         clientContext.Load(sitems);
         clientContext.ExecuteQuery();
         return(sitems.Count == 1 ? new SharePointListItem(sitems[0]) : null);
     }
 }