Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I like to set permission for listitem customlly.But ItemAdded is not firied for listitem. Plz help me

share|improve this question
    
Please elaborate your question, might be can help you better. –  Anuja Oct 26 '12 at 8:20
    
Thanx for ur reply...Event handler is not fired for Item Added. –  varna Oct 26 '12 at 8:23
    
Plz help me.... –  varna Oct 26 '12 at 8:24
add comment

1 Answer

First of all please Download Sharepoint Manger and check if event receiver attached to list or not.

if it is attached properly, in few rare instances where the event handler is not firing.

Does it related to SharePoint timer services or something else?

here is the way you can add event receiver through code.

private void AddEventReceiverToList(string siteUrl, string listName, string className,    string AssemblyFullName)   
{   
using (SPSite site = new SPSite(siteUrl))
using (SPWeb web = site.OpenWeb())   
{   
    try  
    {   
        SPList list = web.Lists[listName];   
        if (list != null)   
        {   
            int receivers = list.EventReceivers.Count;    
            web.AllowUnsafeUpdates = true;   
            bool isAddedReceiverExist = false;   
            for (int i = 0; i < receivers; i++)   
            {   
                SPEventReceiverDefinition eventReceiver = list.EventReceivers[i];   
                if (eventReceiver.Class == className &&  eventReceiver.Type == SPEventReceiverType.ItemAdded)   
                {   
                    isAddedReceiverExist = true;   
                    break;   
                }   
            }   
            if (!isAddedReceiverExist)   
                  list.EventReceivers.Add(SPEventReceiverType.ItemAdded, AssemblyFullName, className);   
        }   
    }   
    catch(Exception exc)
    {
        //magic here
    } 
    finally  
    {   
        web.AllowUnsafeUpdates = false;   
    }   
}   

}  



AddEventReceiverToList("http://spsite-test:231/TestOMatic", "EventReceiverClassName",  "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a865f0ecc234ea51");
share|improve this answer
    
i download Sharepoint Manager.how to check event receiver is attached to list or not using SharePoint Manager –  varna Oct 26 '12 at 8:39
    
you can run SharePoint Manager on your SharePoint server (make sure you do a 'run as administrator' for the first time), then just navigate to your appropriate list, and open up event receivers. It will display everything attached. –  Anuja Oct 26 '12 at 8:48
    
ya i checked by Sharepoint manager....but nothing in the EventReceivers.Wht i have to do now??? –  varna Oct 26 '12 at 9:03
    
That means your event is not attached to the specific list. you can add eventreceiver by code to, i have edited my answer with code, please refer that –  Anuja Oct 26 '12 at 9:08
    
i m creating custom list in the name Sample.And i created the Event Receiver for Item Added.Then what i have to do??? –  varna Oct 26 '12 at 9:17
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.