SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

Got the solution :)

SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            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);
                    gvServices.DataBind();
                }
            }
        });

using SPSecurity.RunWithElevatedPrivileges(delegate() {}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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