1

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

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() {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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