none
How to look at SPList.Items query

    问题

  • Hi,

    I am debugging some legacy code that is getting SPListItem from SPList.Items. Depending on the current users permission, like Visitor or Member, the code returns different items in the SPList.Items collection. The code is working as expected doing some filtering on pages in a document library.

    Here is the legacy code:

    public List<SPListItem> GetListItems(SPList list, string ignoredListItemName, string filterFieldName, string filterFieldValue)
    {
        var pages = new List<SPListItem>();
        if (list == null)
            return pages;
    
        if (list.Items.Count != 0)
        {
            foreach (SPListItem sli in list.Items)
            {
               //Do some filtering stuff based on the ignoredListItemName, filterFieldname and filterFieldValue
                }
                catch (Exception ex)
                {
                    //Do some logging stuff
                }
                if (addIt)
                {
                    pages.Add(sli);
                }
            }
        }
        return pages;
    }


    I have commented out the logic that probably is not relevant...

    When debugger reaches line: if(list.Items.Count !=0)... it already has a different value in the Count property if the user is a Member or a Visitor. So SharePoint must already do some filtering in som query???

    But how can I see the "code" of the query for the different users in list.Items?


    Kind regards

       





    • 已编辑 xaphod 2012年6月28日 9:28 spelling
    2012年6月28日 9:20

答案

  • Hi,

    When you submit the query to the server, security trimming is done on the list items using the context current user.

    So you won't be able to see anything on the query - the context current user will only be able to query the list items he has permissions to.

    Cheers,

    Dan.


    You can find my blog here: http://developertrack.blogspot.com

    2012年6月28日 10:38