Exemplo n.º 1
0
        private static bool IsDefaultField(SPField field)
        {
            var excludedFields = new List <string>
            {
                "LinkTitle2",
                "SyncClientId",
                "HTML_x0020_File_x0020_Type",
                "LinkFilename2",
            };

            return(SPBuiltInFieldId.Contains(field.Id) || excludedFields.Contains(field.InternalName));
        }
 protected void ddl_Lists_SelectedIndexChanged(Object sender, EventArgs e)
 {
     ddl_ListColumns.Enabled = true;
     ddl_ListColumns.Items.Clear();
     using (SPWeb web = SPContext.Current.Web.Site.OpenWeb())
     {
         SPList l = SPContext.Current.Web.Lists[new Guid(ddl_Lists.SelectedValue)];
         foreach (SPField f in l.Fields)
         {
             if (!SPBuiltInFieldId.Contains(f.Id))
             {
                 ddl_ListColumns.Items.Add(new ListItem(f.Title, f.InternalName));
             }
             else if (!cb_UserColumns.Checked)
             {
                 ddl_ListColumns.Items.Add(new ListItem(f.Title + " - " + f.InternalName, f.InternalName));
             }
         }
     }
 }
Exemplo n.º 3
0
        public static SPListItem CloneItem(this SPListItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            SPListItem cloneItem = item.ParentList.AddItem();

            foreach (SPField field in item.Fields)
            {
                if (field.Hidden ||
                    (SPBuiltInFieldId.Contains(field.Id) && field.ReadOnlyField) ||
                    (field.Type == SPFieldType.Calculated ||
                     field.Type == SPFieldType.Attachments ||
                     field.Type == SPFieldType.Counter ||
                     field.Type == SPFieldType.WorkflowStatus))
                {
                    continue;
                }
                cloneItem[field.Id] = item[field.Id];
            }
            return(cloneItem);
        }
Exemplo n.º 4
0
 public static bool IsBuiltInField(this SPField field)
 {
     return(SPBuiltInFieldId.Contains(field.Id));
 }
Exemplo n.º 5
0
        static void TestField(SPWeb spWeb)
        {
            Console.WriteLine("TestField() started...");

            string
                listName  = "Индексы корреспондентов",
                fieldName = "dn_CorrespondentIndexCode";

            SPListItem
                item = spWeb.Lists[listName].Items[0];

            SPField
                field = item.Fields.GetFieldByInternalName(fieldName);

            return;

            string
                listNameFrom = "Чернетки вхідних документів",
                listNameTo   = "Вхідні документи [v2]";

            fieldName = "dn_ct_CitizenExecutedActions";

            SPListItem
                itemFrom = spWeb.Lists[listNameFrom].Items[0];

            int?
                docId;

            if ((docId = GetFieldLookupValue(itemFrom, "dn_ct_IncomingDocProjectDocument")).HasValue)
            {
                SPListItem
                    itemTo;

                try
                {
                    itemTo = spWeb.Lists[listNameTo].GetItemById(docId.Value);

                    foreach (SPField fromField in itemFrom.Fields)
                    {
                        Guid fieldId = fromField.Id;
                        if (SPBuiltInFieldId.Contains(fieldId))
                        {
                            continue;
                        }

                        SPField toField;
                        if (!GetFieldByID(itemTo.Fields, fieldId, out toField))
                        {
                            continue;
                        }

                        try
                        {
                            object
                                tmpObject = itemFrom[fieldId];
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("{0}", fromField.InternalName);
                        }
                    }
                }
                catch (ArgumentException)
                {
                    Console.WriteLine("Doc: {0} - doesn't exist", docId.Value);
                }
            }

            Console.WriteLine("TestField() finished");
            Console.WriteLine();
        }
Exemplo n.º 6
0
        public static DataTable GetEmptyDataTable(SPList list, params Guid[] excludedFieldIds)
        {
            DataTable dt = new DataTable(list.Title);

            SPField fieldId = list.Fields[SPBuiltInFieldId.ID];

            dt.Columns.Add(new DataColumn
            {
                ColumnName = fieldId.InternalName,
                DataType   = typeof(int),
                Caption    = fieldId.Title,
                ReadOnly   = true
            });

            foreach (SPField field in list.Fields)
            {
                if (field.Hidden)
                {
                    continue;
                }

                if ((excludedFieldIds != null && !excludedFieldIds.Contains(field.Id)) && (SPBuiltInFieldId.Contains(field.Id) && field.ReadOnlyField))
                {
                    continue;
                }

                if (field.Type == SPFieldType.Calculated ||
                    field.Type == SPFieldType.Attachments ||
                    field.Type == SPFieldType.Counter ||
                    field.Type == SPFieldType.WorkflowStatus)
                {
                    continue;
                }

                if (dt.Columns.Contains(field.InternalName))
                {
                    continue;
                }

                dt.Columns.Add(new DataColumn
                {
                    ColumnName = field.InternalName,
                    DataType   = field.FieldValueType ?? typeof(string),
                    Caption    = field.Title
                });
            }

            return(dt);
        }