I'm creating a page showing all items from a list. I have enabled versioning for that list. So I want to show the list of all items, even pending items, when a user with contribute permissions is logged in.

DataTable dtserviceDetailsItems = serviceDetailsList.Items.GetDataTable();

How to do that?

1 Answer 1


Got the solution :)

            using (SPSite site = new SPSite(siteId))
                thisWeb = site.OpenWeb();
                SPList serviceDetailsList = thisWeb.Lists["Service Details"];
                if (serviceDetailsList.Items.Count > 0)
                    DataTable dtserviceDetailsItems = serviceDetailsList.GetItems().GetDataTable();
                    dtserviceDetailsItems.Columns.Add("Profile", typeof(string));
                    dtserviceDetailsItems.Columns.Add("Topic", typeof(string));
                    gvServices.DataSource = GetSortedData(dtserviceDetailsItems, gvSortExpression, gvSortDirection);

using SPSecurity.RunWithElevatedPrivileges(delegate() {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.