Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 down vote accepted

Here is the MSDN,

basically

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
1  
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
add comment

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.