예제 #1
0
        public override ContextWraper GetContextWraper()
        {
            try
            {
                var pathContext = HttpContext.Current.Request.Url.PathAndQuery;
                var listTitle   = pathContext.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
                var currentList = _clientContext.Web.Lists;
                _clientContext.Load(currentList, l => l, l => l.Include(i => i.RootFolder));
                _clientContext.ExecuteQuery();
                var camlQueryUrl = string.Format("<View><Query><Where><Eq><FieldRef Name=\"FileRef\"/><Value Type=\"URL\">{0}</Value></Eq></Where></Query></View>",
                                                 pathContext);
                var camlQuery = new CamlQuery();
                camlQuery.ViewXml = camlQueryUrl;
                var selectedList = currentList.FirstOrDefault(i => i.RootFolder.Name.Equals(listTitle));
                var queryRs      = selectedList.GetItems(camlQuery);
                //clientContext.Load(currentList);
                _clientContext.Load(queryRs);
                _clientContext.ExecuteQuery();

                var context = new ContextWraper();
                context.Item       = queryRs.FirstOrDefault().FieldValues;
                context.List       = selectedList.Title;
                context.ListId     = selectedList.Id.ToString("D");
                context.ListItemId = queryRs.FirstOrDefault().Id.ToString();
                return(context);
            }
            catch (Exception e)
            {
                Logger.Unexpected("ClientQuery.GetContextWraper", e);
                return(null);
            }
        }
예제 #2
0
        public override ContextWraper GetContextWraper()
        {
            try
            {
                var listItem = SPContext.Current.ListItem;

                var spContextWraper = new ContextWraper();
                if (listItem != null)
                {
                    spContextWraper.Item = listItem.Fields.Cast <SPField>()
                                           .ToDictionary(i => i.InternalName, i => ValidateValueType(listItem[i.InternalName]));
                    spContextWraper.ListItemId = listItem.ID.ToString();
                }
                spContextWraper.List   = SPContext.Current.List.Title;
                spContextWraper.ListId = SPContext.Current.ListId.ToString("D");
                return(spContextWraper);
            }
            catch (Exception e)
            {
                Logger.Unexpected("ServerQuery.GetContextWraper", e.Message);
                return(null);
            }
        }