Get SharePoint List View Items

This code sample provides method that will get the list items that are present in a SharePoint view.

[csharp]

protected SPListItemCollection GetListViewItems()
{
        return this.GetListViewItems(string.Empty);
}

protected SPListItemCollection GetListViewItems(string viewFields)
{
        try
        {
                SPQuery query = new SPQuery(this.TheListView);
                if ((viewFields != null) && (viewFields.Trim() != string.Empty))
                {
                        query.ViewFields = viewFields;
                }
                return this.TheList.GetItems(query);
        }
        catch (Exception exception)
        {
                this.AddError(exception);
        }
        return null;
}

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *