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 5993539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:41:22+00:00 2026-05-22T23:41:22+00:00

I have created an event handler for ItemAdded so that when an item is

  • 0

I have created an event handler for ItemAdded so that when an item is added on the site, my code checks to see if it’s a folder. If it is, it should change the content type of that folder to a custom content type.

The event isn’t firing, so I was wondering if I’m doing it the right way and/or in the right place. Here is my code:

public class ItemAddedHandler : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);

    SPListItem listItem = properties.ListItem;
    SPList list = properties.ListItem.ParentList;
    SPContentType contentType;

    if (listItem.FileSystemObjectType == SPFileSystemObjectType.Folder &&
       (list.Title == "Apps" || list.Title == "Data" || list.Title == "Public"))
    {
        contentType = list.ContentTypes["Custom Folder"];

        listItem["Content Type"] = contentType.Name;
        listItem["Content Type ID"] = contentType.Id.ToString();
        listItem.SystemUpdate();
    }
}
}

Please let me know if I’m doing anything wrong to accomplish this task. Thanks very much in advance.

As requested, the feature was adding with the following method:

  1. Signed and compiled above code and copied DLL to server
  2. Copied DLL to GAC
  3. Created folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\SPEventHandler
    4.Created Feature.xml using GUID generated with Visual Studio:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature Scope="Web" 
      Title="Added Event Handler" 
      Id="{27C2FDFF-ADA0-4984-955C-6448E182FA88}" 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="Elements.xml"/>
      </ElementManifests>
    </Feature>
    

5.Created Elements.xml using PublicKeyToken of DLL in GAC and ListTemplateID for working with a document library (101):

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Receivers ListTemplateId="101">
        <Receiver>
          <Name>AddedEventHandler</Name>
          <Type>ItemAdded</Type>
          <SequenceNumber>10000</SequenceNumber>
          <Assembly>SPEventHandler, Version=1.0.0.0, Culture=neutral, 
              PublicKeyToken=f2e7de6c4a924a03</Assembly>
          <Class>SPEventHandler.ItemAddedHandler</Class>
          <Data></Data>
          <Filter></Filter>
        </Receiver>
      </Receivers>
    </Elements>
  1. Ran the following command on the server:

    stsadm -o installfeature -filename SPEventHandler\Feature.xml

  2. On the site (SP 2007), Site Actions -> Site Settings -> Modify All Site Settings -> Site features and activated “Added Event Handler”

After these steps, creating a new item in a list on this site does not seem to do anything, including writing to the event log, so I’m wondering if it is even getting run at all.

Thanks

  • 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-05-22T23:41:22+00:00Added an answer on May 22, 2026 at 11:41 pm

    I figured it out. My custom content type needed to be enabled for the document library before an item could be given that content type. Thanks everyone for your responses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a mouse event handler that gives me the screen coordinate (X,Y)
I have created a new WPF application and added an event handler for Loaded
I have simple SSIS package in which On Error event handler I have created
In my Silverlight app I have an event handler that dynamically creates a new
I have a global event created and set/reset in a native C++ process that
I have an application that has created a number of custom event log sources
I have created an event handler for the OnSortCommand of DataGrid: <asp:DataGrid id=dtgBatches runat=server
I have created a custom event in flex 3.5. But the handler is not
I have an ASP.NET web form. This web form has an event handler that
I have created a custom event to handle how the data should be updated

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.