0

I want to disable list throttling through code so i have written the following code

SPList lstBookings = web.Lists.TryGetList("Bookings");
                    lstBookings.EnableThrottling = false;

But does this requires the code to be running under elevated privileges, because if i login as a non admin user it gives me an error cannot login.

Anyone any ideas?

Thanks.

1
  • RunWithElevatedPriviledges doesnot solve this problem?
    – variable
    Jul 24 '14 at 11:11
3

EnableThrottling seems to require Farm Administrator privileges. Take a look at the following code:

public bool EnableThrottling
{
    get { ... }
    set
    {
        bool nothrottlevalue = !value;
        this.SetListNoThrottle(nothrottlevalue);
    }
} 

internal void SetListNoThrottle(bool nothrottlevalue)
{
    SPSite site = this.ParentWeb.Site;
    if (!site.WebApplication.Farm.CurrentUserIsAdministrator(true))
        SPGlobal.HandleUnauthorizedAccessException(new UnauthorizedAccessException());
    else
        { ... }
}

The system account, in turn, has Site Collection Administrator privilege. The SPSecurity.RunWithElevatedPrivileges allows to run code under the Application Pool identity, which has same Site Collection Administrator privileges on all site collections.

0

Run this piece of code as the Application Pool identity user:

SPSecurity.RunWithElevatedPriveleges( () => {
     using (var site = new SPSite(SPContext.Current.Site.ID))
                {
                    var web = site.RootWeb;
                    var lstBookings = web.Lists.TryGetList("Bookings");
                    lstBookings.EnableThrottling = false;
                    lstBookings.Update();
                }
});

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.