GetAccessibleSharePointColumns(string sharepointUrl, string listName, string viewName)
        {
            List <SharePointUtility.DataObject.ColumnData> columnList =
                ListServiceUtility.GetFields(new Uri(sharepointUrl), _credentials, listName, viewName);

            // Pull out the ID Field because we want this to be first in the list, and the other columns
            // will keep their order that SharePoint sends them.
            var idField =
                from c in columnList
                where (c.Name == "ID" || c.Name == "FsObjType")
                select c;

            var accessibleColumns =
                from c in columnList
                where (!c.IsHidden && !c.IsReadOnly)
                select c;

            return(idField.Union(accessibleColumns).ToList());
        }
Beispiel #2
0
        /// <summary>
        /// Get the columns that are public
        /// </summary>
        /// <param name="sharepointUrl"></param>
        /// <param name="listName"></param>
        /// <returns></returns>
        private List <SharePointUtility.DataObject.ColumnData> GetAccessibleSharePointColumns(string sharepointUrl, string listName, string viewName)
        {
            List <SharePointUtility.DataObject.ColumnData> columnList =
                ListServiceUtility.GetFields(new Uri(sharepointUrl), _credentials, listName, viewName);

            // Pull out the ID Field because we want this to be first in the list, and the other columns
            // will keep their order that SharePoint sends them.
            var idField =
                from c in columnList
                where c.Name == "ID"
                select c;

            bool expandLookups         = false;
            var  expandLookupsProperty = FindCustomProperty(C_DECODELOOKUPS);

            if ((Enums.TrueFalseValue)expandLookupsProperty.Value == Enums.TrueFalseValue.True)
            {
                expandLookups = true;
            }


            // Consult the property to determine if we're doing any filtering here
            bool includeHidden         = false;
            var  includeHiddenProperty = FindCustomProperty(C_INCLUDEHIDDEN);

            if ((Enums.TrueFalseValue)includeHiddenProperty.Value == Enums.TrueFalseValue.True)
            {
                includeHidden = true;
            }

            var accessibleColumns =
                from c in columnList
                where ((c.IsHidden == includeHidden ||
                        c.IsHidden == false) && c.IsInView == true)
                select c;

            if (expandLookups)
            {
                // Add the columns that are not raw and remove the 'raw' columns.
                var lookupColumns =
                    from c in accessibleColumns
                    where c.LookupFieldDisplay != SharePointUtility.DataObject.ColumnData.EncodedFieldDisplayEnum.DisplayRaw
                    select c;

                var exclusionList =
                    from x in accessibleColumns
                    join c in lookupColumns on x.SourceFieldName equals c.SourceFieldName
                    where x.LookupFieldDisplay == SharePointUtility.DataObject.ColumnData.EncodedFieldDisplayEnum.DisplayRaw
                    select x;

                var outputColumns = accessibleColumns.Except(exclusionList);

                return(idField.Union(outputColumns).ToList());
            }
            else
            {
                // Add the columns that are not raw and remove the 'raw' columns.
                var lookupColumns =
                    from c in accessibleColumns
                    where c.LookupFieldDisplay != SharePointUtility.DataObject.ColumnData.EncodedFieldDisplayEnum.DisplayRaw
                    select c;

                var outputColumns = accessibleColumns.Except(lookupColumns);

                return(idField.Union(outputColumns).ToList());
            }
        }