Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am quite new to SharePoint and have been working on this thing for a couple of days. I was able to somehow use ItemAdded event receiver but I want if I update List 1 then using ItemUpdated event receiver List 2 should also get updated. I am struggling with the coding part. How to link items in one list with another and then how to update.

share|improve this question
1  
What code do you have so far in your ItemUpdated event receiver? –  mikey Feb 21 '13 at 5:45
    
I can share ItemAdded code. ItemUpdated one is too messy. base.ItemAdded(properties); try{base.EventFiringEnabled = false; using (SPSite site = properties.OpenSite()) {using (SPWeb web = site.OpenWeb()) {SPList list = web.Lists["Cust_3"]; SPItem item = list.Items.Add(); item["Title"] = properties.ListItem["Title"]; item["Col1"] = properties.ListItem["Col1"]; item["Col2"] = properties.ListItem["Col2"]; item.Update(); }}} –  Sane.Amit Feb 21 '13 at 5:52
add comment

1 Answer

Here is an example "ItemAdded" event -- your itemupdating event can work similar to this. In this example, any time a new item is added to my "Tasks" list, the event receiver adds a similar item to my "Skills and Abilities" list:

        // ITEM ADDED
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);

            try
            {
                String curListName = properties.ListTitle;
                if (_applicableLists.Contains(curListName))
                {

                    if (properties.ListItem.ContentType.Name == "Discussion")
                    {

                        if (curListName == "Tasks")
                        {
                            SPList saList = properties.Web.Lists["Skills & Abilities"];
                            SPListItem saItem = SPUtility.CreateNewDiscussion(saList, properties.ListItem["Task Text"].ToString());
                            SPFieldLookupValue taskLookup = new SPFieldLookupValue();
                            taskLookup = new SPFieldLookupValue(properties.ListItem.ID, (string)properties.AfterProperties["Task ID"]);
                            saItem["Task Lookup"] = taskLookup;
                            saItem["Title"] = properties.ListItem["Task Text"].ToString();
                            saItem["Body"] = "Please leave a comment by clicking the Reply link on the right of this message.";
                            saItem[_inStatus] = "New";
                            // perform the update with event firing disabled
                            EventFiringEnabled = false;
                            saItem.Update();
                            EventFiringEnabled = true;

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // handle exception...
            }
        }

I also urge you to check out the sharepoint.stackexchange.com site for a focus on SharePoint. Good luck!

share|improve this answer
add comment

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.