Exemplo n.º 1
0
        private void ReadFromListItem()
        {
            foreach (PropertyInfo pInfo in SPFieldMetadata.GetProperties(this.GetType()))
            {
                try
                {
                    SPFieldMetadata metadata = SPFieldMetadata.Get(pInfo);
                    object          value;
                    try { value = metadata.GetFieldValue(_item); }
                    catch (ArgumentException e)
                    {
                        if (_throwFieldErrors)
                        {
                            throw e;
                        }

                        continue;
                    }
                    pInfo.GetSetMethod(true).Invoke(this, new[] { value });
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Error processing list item. Property: {0} -- Item: {1} -- Inner Exception: {2}", pInfo.Name, _item != null ? _item.Title : "NULL", e.ToString()));
                }
            }
        }
Exemplo n.º 2
0
        protected override Expression VisitMember(MemberExpression node)
        {
            SPFieldMetadata     md       = SPFieldMetadata.Get((PropertyInfo)node.Member);
            CamlFieldExpression fieldExp = new CamlFieldExpression(md.InternalName, md.Type);

            if (!_withinExpression)
            {
                if (node.Type.Equals(typeof(bool)))
                {
                    return(new CamlComparisonExpression(SPQueryNodeType.Equals, fieldExp, new CamlValueExpression(true, node.Type)));
                }

                throw new NotSupportedException();
            }

            return(fieldExp);
        }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            using (SPCtx ctx = new SPCtx(_siteUrl))
            {
                ctx.Web.ContentTypes.EnsureContentType(SPContentTypeMetadata.Get(typeof(FormSubmissionItem)), ctx.Web);
                ctx.Web.Fields.EnsureFields(SPFieldMetadata.GetMetadata(typeof(FormSubmissionItem)));
                ctx.Web.ContentTypes.EnsureFieldLinks(SPFieldMetadata.GetMetadata(typeof(FormSubmissionItem)), ctx.Web.Fields);
                //FormSubmissionList list = ctx.Web.GetList<FormSubmissionList>(true);
                FormSubmissionList list = new FormSubmissionList(true);
                list.LoadList(ctx.Web, true);
                list.EnsureList();

                /* var item = list.AddItem();
                 * Console.WriteLine(item.ContentType);
                 *
                 *
                 * item.SubmitValue = "whatever";
                 * item.Update();
                 * Console.WriteLine(item.ContentType); */
            }
        }
Exemplo n.º 4
0
 private void WriteToListItem()
 {
     foreach (PropertyInfo pInfo in SPFieldMetadata.GetProperties(this.GetType()))
     {
         SPFieldMetadata metadata = SPFieldMetadata.Get(pInfo);
         try
         {
             if (!metadata.ReadOnly)
             {
                 metadata.SetFieldValue(_item, pInfo.GetGetMethod(true).Invoke(this, null));
             }
         }
         catch (ArgumentException e)
         {
             if (_throwFieldErrors)
             {
                 throw e;
             }
         }
     }
 }
Exemplo n.º 5
0
 public static bool ContainsField(this SPFieldCollection fieldCollection, SPFieldMetadata fieldMetadata)
 {
     return(fieldMetadata.IsIn(fieldCollection));
 }
Exemplo n.º 6
0
 public static void Add(this SPFieldCollection fieldCollection, SPFieldMetadata fieldMetadata)
 {
     fieldMetadata.AddFieldTo(fieldCollection);
 }
Exemplo n.º 7
0
 public static void EnsureContentType <T>(this SPWeb web) where T : SPTypedListItem, new()
 {
     web.ContentTypes.EnsureContentType(SPContentTypeMetadata.Get(typeof(T)), web);
     web.Fields.EnsureFields(SPFieldMetadata.GetMetadata(typeof(T)));
     web.ContentTypes.EnsureFieldLinks(SPFieldMetadata.GetMetadata(typeof(T)), web.Fields);
 }
Exemplo n.º 8
0
 public static SPField GetField(this SPFieldCollection fieldCollection, SPFieldMetadata fieldMetadata)
 {
     return(fieldMetadata.GetField(fieldCollection));
 }
Exemplo n.º 9
0
        protected override Expression VisitMember(MemberExpression node)
        {
            SPFieldMetadata md = SPFieldMetadata.Get((PropertyInfo)node.Member);

            return(Expression.Constant(md.InternalName));
        }