itemadded イベント レシーバーを備えたドキュメント ライブラリがあります。ドキュメント ライブラリ内のアイテムはドキュメント セットです。
ドキュメント ライブラリにアイテムを作成すると、追加されたアイテムが実行されます。ただし、そのロジックは、ファイルをドキュメント セットに追加するときではなく、ドキュメント セット自体に対してのみ実行したいと考えています。
次のコードは、ドキュメント セットを作成するときに正常に機能しますが、次の行:
string recurrent = item[Meetings.Common.Constants.FIELDS_AGENDAPOINTSRECURRENT_NAME].ToString();
ファイルがドキュメント セットにアップロードされたときにイベント レシーバーが実行されると、オブジェクト参照例外をスローします。
public override void ItemAdded(SPItemEventProperties properties)
{
Logger.LogDebug("AgendaPointsProposedEvents", "ItemAdded(SPItemEventProperties properties)", "BEGIN");
base.ItemAdded(properties);
try
{
base.EventFiringEnabled = false;
SPListItem item = properties.ListItem;
SPItemEventDataCollection afterProperties = properties.AfterProperties;
string listName = item.ParentList.RootFolder.Name;
string recurrent = item[Meetings.Common.Constants.FIELDS_AGENDAPOINTSRECURRENT_NAME].ToString();
bool recurrentBln = bool.Parse(recurrent);
if (recurrentBln)
{
#region NLNSSV-169
// If the user selects recurrent the agenda proposed item cant have an associated meeting.
// Also the security is reset to its initial state.
properties.ListItem[Meetings.Common.Constants.FIELDS_MEETING_NAME] = null;
properties.List.ResetRoleInheritance();
properties.ListItem.Update();
#endregion
}
else
{
#region NLNSSV-184
// NLNSSV-184
// Proposed meeting points should be visible to other departments as soon as they are added to a meeting.
// An event handler should change the authentication on the item level when a meeting point is added to (or removed from!) the meeting.
// This also needs a change in the views and screens..
SPFieldLookup sp = item.GetLookupField(MeetingsCommon.Constants.FIELDS_MEETING_NAME);
string meetingname = afterProperties.GetValueAsString("Meeting");
if (!string.IsNullOrEmpty(meetingname))
{
RoleDefRead = SecurityHelper.GetRoleDefinition(properties.Web, Constants.PERMISSIONLEVEL_READ);
DepartmentCORUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTCORUSERS_NAME];
DepartmentFINUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTFINUSERS_NAME];
DepartmentMSCUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTMSCUSERS_NAME];
DepartmentOPIUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTOPIUSERS_NAME];
DepartmentRDSUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTRDSUSERS_NAME];
DepartmentSALUsersGroup = properties.Web.SiteGroups[MeetingsCommon.Constants.SECURITY_PRINCIPAL_DEPARTMENTSALUSERS_NAME];
bool isProposed = item.TaxonomyFieldValueIsGivenValue(properties.AfterProperties, MeetingsCommon.Constants.FIELDS_AGENDAPOINTSTATUS_NAME, MeetingsCommon.Constants.TERMVALUE_AGENDAPOINTSTATUS_PROPOSED, 1033);
if (isProposed)
{
#region Change permissions in COR items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDCOR_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentFINUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentMSCUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentOPIUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentRDSUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentSALUsersGroup, false); // Read
}
#endregion
#region Change permissions in FIN items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDFIN_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentCORUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentMSCUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentOPIUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentRDSUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentSALUsersGroup, false); // Read
}
#endregion
#region Change permissions in MSC items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDMSC_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentCORUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentFINUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentOPIUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentRDSUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentSALUsersGroup, false); // Read
}
#endregion
#region Change permissions in OPI items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDOPI_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentCORUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentFINUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentMSCUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentRDSUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentSALUsersGroup, false); // Read
}
#endregion
#region Change permissions in RDS items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDRDS_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentCORUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentFINUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentMSCUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentOPIUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentSALUsersGroup, false); // Read
}
#endregion
#region Change permissions in SAL items
if (listName.Equals(MeetingsCommon.Constants.LISTS_AGENDAPOINTSPROPOSEDSAL_NAME))
{
item.BreakRoleInheritance(true);
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentCORUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentFINUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentMSCUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentOPIUsersGroup, false); // Read
SecurityHelper.AddToRoleAssignment(RoleDefRead, properties.Web, item, DepartmentRDSUsersGroup, false); // Read
}
#endregion
}
}
else
{
item.ResetRoleInheritance();
}
#endregion
}
}
catch (Exception ex)
{
Logger.LogError("AgendaPointsProposedEvents", "ItemAdded(SPItemEventProperties properties)", ex);
throw;
}
finally
{
base.EventFiringEnabled = true;
}
Logger.LogDebug("AgendaPointsProposedEvents", "ItemAdded(SPItemEventProperties properties)", "END");
}