Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:35:53+00:00 2026-06-09T12:35:53+00:00

I have a document library with an itemadded event receiver. Items in the document

  • 0

I have a document library with an itemadded event receiver. Items in the document library are document sets.

when I create an item in the document library, the item added is executed. However that logic, I want to execute it only for the document set itself and not when I add a file INTO the document set.

the following code works fine when creating the document set, but the line:

string recurrent = item[Meetings.Common.Constants.FIELDS_AGENDAPOINTSRECURRENT_NAME].ToString();

throw object reference exception when the event receiver is executed when a file is uploaded to the document set

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");
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:35:54+00:00Added an answer on June 9, 2026 at 12:35 pm

    I figured it out.

    THe idea is to detect the contentype because sometimes a list might have different content types and you want the code to execute only for one contenttype.

    easy:

     string contentTypeName = properties.ListItem.ContentType.Name;
                if (contentTypeName == "contentypename")
                {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added a menu item in edit control block(ECB) in document library(using following
I have added a menu item in ECB of document of document library. On
I have a document library with a workflow that dynamicly sets user permissions to
For example, I have a document library that hold contracts for multiple projects. So:
We have a web part that uploads a document to a document library. The
In SharePoint, when an item is first added to a document library, it fires
I have a document library that I am accessing programmatically as an SPList .
I have a loop that is looping through a document library like in the
I have a document library list. I created folders in that list and uploaded
I have a ASP.NET intranet application that has a document library section. The user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.