SharePoint Helper Class

SPWeb web = properties.Feature.Parent as SPWeb;

try
{
//Register and Unregister SharePoint timer job
d.SharePoint.SPJob.JobFactory.Register("myTimerJob", web, new SPHourlySchedule() { BeginMinute = 10, EndMinute = 30 });
d.SharePoint.SPJob.JobFactory.Unregister("myTimerJob", web);

//Register and Unregister SharePoint receiver
d.SharePoint.SPReceiver.ReceiverFactory.Register(web, "MyList", SPEventReceiverType.ItemAdding);
d.SharePoint.SPReceiver.ReceiverFactory.Unregister(web, "MyList", SPEventReceiverType.ItemAdding);

//Run code with different privileges
d.SharePoint.PortalSecurity.RunWithElevatedPrivileges(() => { web.EnsureUser(""); });
d.SharePoint.PortalSecurity.RunWithElevatedPrivileges(web, (elevatedSite, elevatedWeb) => { elevatedWeb.Update(); });
d.SharePoint.PortalSecurity.RunWithUserPriveleges(web, web.Users["someUser"], (elevatedSite, elevatedWeb) => { elevatedWeb.Update(); });
}
catch (Exception ex)
{
// log uls
d.SharePoint.SPLog.Log(ex);
d.SharePoint.SPLog.Log("FeatureActivated", ex);
}

https://github.com/dzsoft-ru/d.SharePoint

Добавить комментарий

Loading