SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

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 trying to set the ChangeLogRetentionPeriod stsadm property from code, which is normally set from the SP powershell.

What is the best way to go about setting this property from code?

Background: I am making use of the SP 2010 auditing from a foundation instance, and trying to build a UI front-end for administrators to easily set audit settings (since the UI is not available in foundation).

share|improve this question
up vote 2 down vote accepted

Here is the MSDN,


using(var site = new SPSite(SPContext.Current.Site.ID))
    var webapp = site.WebApplication;
    webapp.ChangeLogRetentionPeriod = new TimeSpan(1,0,0,0); // meaning 1 day

The code must be executed by a Farm Administrator account, so you might need to do som impersonification in the new SPSite statement, like new SPSite(SPContext.Current.Site.ID, farmAdminUserRetrievedBefore.UserToken)

share|improve this answer
Not sure how I missed this in MSDN. Elevating permissions is a key point, so I am glad you mentioned that. – Ray Jun 20 '13 at 14:54

Your Answer


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.