本文整理汇总了C#中SPItemEventProperties类的典型用法代码示例。如果您正苦于以下问题:C# SPItemEventProperties类的具体用法?C# SPItemEventProperties怎么用?C# SPItemEventProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SPItemEventProperties类属于命名空间,在下文中一共展示了SPItemEventProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemUpdating
/// <summary>
/// An item is being updated.
/// </summary>
public override void ItemUpdating(SPItemEventProperties properties)
{
bool allowed = true;
if (properties.ListTitle == "Open Positions")
{
allowed = checkItem(properties);
}
try
{
if (!allowed)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "The job you have entered is not defined in the Job Definitions List";
properties.Cancel = true;
}
}
catch (Exception ex)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = ex.Message;
properties.Cancel = true;
}
}
示例2: GiveUserPrivelegesToWorkspace
private void GiveUserPrivelegesToWorkspace(SPUser user, SPItemEventProperties properties)
{
InitializeWebAppProperties(properties);
string workspaceURL = properties.Web.ServerRelativeUrl;
//workspaceURL = workspaceURL.Remove(0, emisSiteURL.Length);
workspaceURL = workspaceURL.Substring(workspaceURL.IndexOf("Agenda-"));
using (SPSite emisSite = new SPSite(emisSiteURL))
{
using (SPWeb currentWorkspace = emisSite.OpenWeb(workspaceURL))
{
currentWorkspace.AllowUnsafeUpdates = true;
SPRoleAssignment role;
role = new SPRoleAssignment(currentWorkspace.EnsureUser(user.LoginName));
role.RoleDefinitionBindings.Add(currentWorkspace.RoleDefinitions["Restricted Contribute"]);
currentWorkspace.RoleAssignments.Add(role);
currentWorkspace.AllowUnsafeUpdates = false;
currentWorkspace.Update();
}
}
}
示例3: GetLatestItemOrderNo
private int GetLatestItemOrderNo(SPItemEventProperties properties)
{
int orderNo = 0;
string caml = string.Empty;
var expressionsAnd = new List<Expression<Func<SPListItem, bool>>>();
if (expressionsAnd.Count > 0)
caml = Camlex.Query().WhereAll(expressionsAnd).OrderBy(x => x[Constants.ORDER_NUMBER_COLUMN] as Camlex.Desc).ToString();
else
caml = Camlex.Query().OrderBy(x => x[Constants.ORDER_NUMBER_COLUMN] as Camlex.Desc).ToString();
SPQuery spQuery = new SPQuery();
spQuery.Query = caml;
spQuery.RowLimit = 1;
SPList currentList = properties.List;
SPListItemCollection items = currentList.GetItems(spQuery);
if (items != null && items.Count > 0)
{
SPListItem item = items[0];
if (item != null)
{
orderNo = Convert.ToInt32(item[Constants.ORDER_NUMBER_COLUMN]);
}
}
return orderNo;
}
示例4: EventReceiverContext
public EventReceiverContext(SPItemEventProperties properties)
{
Site = new SPSite(properties.SiteId);
Web = Site.OpenWeb(properties.RelativeWebUrl);
List = Web.Lists[properties.ListId];
Item = List.GetItemByIdAllFields(properties.ListItemId);
}
示例5: AddFileInfo
private void AddFileInfo(SPItemEventProperties properties)
{
try
{
var url = properties.WebUrl + "/" + properties.AfterUrl;
var fileName = properties.AfterUrl;
using (var site = new SPSite(properties.Web.Site.ID))
using (var web = site.RootWeb)
{
var list = web.Lists[LogList.ListName];
var listItems = list.Items;
var item = listItems.Add();
item["Title"] = fileName;
item["URL"] = url;
item.Update();
}
ULSLog.LogDebug(String.Format("Added {0} to {1} list", url, LogList.ListName));
}
catch (Exception ex)
{
ULSLog.LogError(ex);
}
}
示例6: Execute
private void Execute(SPItemEventProperties properties)
{
this.EventFiringEnabled = false;
try
{
BLL.Logger.LogEvent(properties.WebUrl, properties.ListItem.Title + ".OnChange");
SPListItem item = properties.ListItem;
SPWeb web = properties.Web;
Update_LookupRefFields(item);
Update_FolderInLibrary(item, web);
}
catch (Exception ex)
{
BLL.Logger.LogEvent(properties.WebUrl, ex.ToString());
var result = ElasticEmail.EmailGenerator.ReportError(ex, properties.WebUrl.ToString());
}
finally
{
this.EventFiringEnabled = true;
}
}
示例7: GetSPUser
private SPUser GetSPUser(SPItemEventProperties properties, string key)
{
string rawUserName = Convert.ToString(properties.AfterProperties["AssignedTo"]);
int separatorIndex = rawUserName.IndexOf(";#");
string claimsUserName = rawUserName.Substring(separatorIndex + 2);
SPClaimProviderManager claimsManager = SPClaimProviderManager.Local;
string userName = null;
if (claimsManager != null)
{
userName = claimsManager.DecodeClaim(claimsUserName).Value;
}
return properties.Web.EnsureUser(userName);
//SPContentType martaTaskCT = properties.Web.ContentTypes["MARTATask"];
//SPFieldUser field = martaTaskCT.Fields[key] as SPFieldUser;
//if (field != null)
//{
// SPFieldUserValue fieldValue = field.GetFieldValue(Convert.ToString(properties.AfterProperties["AssignedTo"])) as SPFieldUserValue;
// if (fieldValue != null)
// {
// return fieldValue.User;
// }
//}
//return null;
}
示例8: Execute
private void Execute(SPItemEventProperties properties)
{
this.EventFiringEnabled = false;
try
{
BLL.Logger.LogEvent(properties.WebUrl, properties.ListItem.Title + ".OnUpdate");
SPListItem item = properties.ListItem;
if (item.Title.StartsWith(":"))
{
item["_DISPLAY"] = item.Title;
}
else
{
item["_DISPLAY"] = string.Format("{0}::{1}",
item["selGrupaProcedury"] != null ? new SPFieldLookupValue(item["selGrupaProcedury"].ToString()).LookupValue : string.Empty,
item.Title);
}
item.SystemUpdate();
}
catch (Exception ex)
{
BLL.Logger.LogEvent(properties.WebUrl, ex.ToString());
var result = ElasticEmail.EmailGenerator.ReportError(ex, properties.WebUrl.ToString());
}
finally
{
this.EventFiringEnabled = true;
}
}
示例9: ItemAdded
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
SPWeb spWeb = properties.Web;
SPPushNotificationSubscriberCollection pushSubscribers = spWeb.PushNotificationSubscribers;
PushNotification pushNotification = new PushNotification();
SPListItem listItem = properties.ListItem;
string jobAssignment = "[Unassigned]";
// This event receiver is intended to be associated with a specific list,
// but the list may not have an "AssignedTo" field, so using try/catch here.
try
{
jobAssignment = listItem["AssignedTo"].ToString();
}
catch { }
PushNotificationResponse pushResponse = null;
foreach (SPPushNotificationSubscriber ps in pushSubscribers)
{
// Send a toast notification to be displayed on subscribed phones on which the app is not running.
pushResponse = pushNotification.PushToast(ps, "New job for:", jobAssignment, string.Empty, ToastIntervalValuesEnum.ImmediateToast);
UpdateNotificationResultsList(spWeb, ps.User.Name, pushResponse);
// Also send a raw notification to be displayed on subscribed phones on which the app is running when the item is added.
pushResponse = pushNotification.PushRaw(ps, string.Format("New job for: {0}", jobAssignment), RawIntervalValuesEnum.ImmediateRaw);
UpdateNotificationResultsList(spWeb, ps.User.Name, pushResponse);
}
base.ItemAdded(properties);
}
示例10: ItemUpdating
public override void ItemUpdating(SPItemEventProperties properties) {
string title = properties.AfterProperties["Title"].ToString();
if (title.ToLower().Contains("lobster") || title.ToLower().Contains("clam")) {
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Do not use inflamitory terms such as 'lobster' or'clam'.";
}
}
示例11: ItemUpdated
/// <summary>
/// Asynchronous After event that occurs after an existing item is changed, for example, when the user changes data in one or more fields.
/// </summary>
/// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPItemEventProperties" /> object that represents properties of the event handler.</param>
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
using (var childScope = NavigationContainerProxy.BeginWebLifetimeScope(properties.Web))
{
this.EventFiringEnabled = false;
var logger = childScope.Resolve<ILogger>();
try
{
var navigationTermService = childScope.Resolve<INavigationTermBuilderService>();
var variationHelper = childScope.Resolve<IVariationHelper>();
var item = properties.ListItem;
// If the content is created at the source label, sync the term
if (variationHelper.IsCurrentWebSourceLabel(item.Web))
{
// Create term in other term sets
navigationTermService.SyncNavigationTerm(properties.ListItem);
}
}
catch (Exception e)
{
logger.Exception(e);
}
finally
{
this.EventFiringEnabled = true;
}
}
}
示例12: ItemUpdated
public override void ItemUpdated(SPItemEventProperties properties)
{
SPListItem item1 = properties.ListItem;
var delemans = item1["Delegates"].AsString();
if (delemans.AsString().IsNullOrWhitespace())
{
return;
}
char[] split = { '#' };
string[] deles = delemans.Split(split);
List<SPPrincipal> principals = new List<SPPrincipal>();
for (int i = 0; i < deles.Length; i++)
{
if (deles[i].IsNullOrWhitespace())
{
continue;
}
principals.Add(item1.Web.Users[deles[i]]);
}
if (principals.Count > 0)
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb("WorkFlowCenter"))
{
try
{
SPListItem item = web.Lists["Travel Request Workflow2"].GetItemById(item1.ID);
if (!item.HasUniqueRoleAssignments)
{
item.BreakRoleInheritance(true);
}
SPRoleDefinition AdminRoleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Administrator);
SPRoleDefinition GuestRoleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Guest);
foreach (SPPrincipal principal in principals)
{
SPRoleAssignment RoleAssignment = new SPRoleAssignment(principal);
RoleAssignment.RoleDefinitionBindings.Add(AdminRoleDefinition);
RoleAssignment.RoleDefinitionBindings.Remove(GuestRoleDefinition);
item.RoleAssignments.Remove(principal);
item.RoleAssignments.Add(RoleAssignment);
}
item["Delegates"] = string.Empty;
base.DisableEventFiring();
item.Update();
base.EnableEventFiring();
}
catch (Exception ex)
{
//TO-DO
}
}
}
});
}
}
示例13: ItemUpdated
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
SPListItem listItem = properties.ListItem;
HandleSecurityRules(listItem, properties.EventType);
}
示例14: checkItem
bool checkItem(SPItemEventProperties properties)
{
string jobTitle = properties.AfterProperties["Title"].ToString();
bool allowed = false;
SPWeb jobDefWeb = null;
SPList jobDefList;
SPUser privilegedAccount = properties.Web.AllUsers[@"SHAREPOINT\SYSTEM"];
SPUserToken privilegedToken = privilegedAccount.UserToken;
try
{
using (SPSite elevatedSite = new SPSite(properties.Web.Url, privilegedToken))
{
using (SPWeb elevatedWeb = elevatedSite.OpenWeb())
{
jobDefWeb = elevatedWeb.Webs["JobDefinitions"];
jobDefList = jobDefWeb.Lists["Job Definitions"];
foreach (SPListItem item in jobDefList.Items)
{
if (item["Title"].ToString() == jobTitle)
{
allowed = true;
break;
}
}
}
}
return (allowed);
}
finally
{
jobDefWeb.Dispose();
}
}
示例15: GetKeyPeopleForAgenda
public static SPFieldUserValueCollection GetKeyPeopleForAgenda(string agendaType, string agmOffice, SPItemEventProperties eventProperties)
{
string masterKeyPeopleListName = null;
//SPFolder defaultDocuments =rootWeb.RootWeb.Folders["Default Documents"];
SPWebApplication webApplication = eventProperties.Web.Site.WebApplication;
if (webApplication.Properties != null && webApplication.Properties.Count > 0)
{
masterKeyPeopleListName = webApplication.Properties["MasterKeyPeopleListName"].ToString();
}
SPList list = eventProperties.Web.Lists[masterKeyPeopleListName];
SPFieldUserValueCollection authUsers = new SPFieldUserValueCollection();
if (list != null)
{
foreach (SPListItem item in list.Items)
{
if ((item["Agenda Type"].ToString() == agendaType) && (item["AGM Office"].ToString() == agmOffice) && (item["Position"].ToString() == "Agenda Coordinator"))
{
string authUsersFieldValue = item["KeyPerson"].ToString();
authUsers.Add(new SPFieldUserValue(item.Web, authUsersFieldValue));
//break;
}
}
return authUsers;
}
else
return null;
}