Продолжаю заполнять свой GitHub.
Очень полезные методы при работе с SharePoint.
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);
}
[Ещё]
Начинаю заполнять свой репозиторий на GitHub.
Методы помогающие при работе с сессией, кэшем и параметрами веб формы.
//get key from session
int someKey1 = d.Web.Helper.Session.Get("someKey");
int someKey2 = HttpContext.Current.Session.Get("someKey");
//if key not exists return value from function and insert to cache
int someKey3 = d.Web.Helper.Session.TryGet("someKey", () => { return 0; });
int someKey4 = d.Web.Helper.Session.TryGet("someKey", CreateNewSessionFunction );
//get key from cache
int someKey1 = d.Web.Helper.Cache.Get("someKey");
int someKey2 = HttpRuntime.Cache.Get("someKey");
//if key not exists return value from function and insert to cache
int someKey3 = d.Web.Helper.Cache.TryGet("someKey", () => { return 0; });
int someKey4 = HttpRuntime.Cache.TryGet("someKey", new TimeSpan(1000), CreateNewCacheFunction);
Web Form helper
//get value from HttpContext.Current.Request.QueryString
d.Web.Helper.Form.QueryValue("someKey");
d.Web.Helper.Form.QueryValue("someKey", "",",");
d.Web.Helper.Form.QueryValue("someKey", "yyyyMMdd");
//get value from HttpContext.Current.Request.Params
d.Web.Helper.Form.PostValue("someKey");
d.Web.Helper.Form.PostValue("someKey", "", ",");
d.Web.Helper.Form.PostValue("someKey", "yyyyMMdd");
[Ещё]