How can I access/set stsadm properties from code?
Question
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).
Solution
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)
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange