Click here to Skip to main content
13,260,108 members (51,156 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


21 bookmarked
Posted 23 Oct 2008

Working with two or more SharePoint Lists

, 23 Oct 2008
Rate this:
Please Sign up or sign in to vote.
Updating different List values from an event occuring in a List.


Normally when we want to update different number of list values during an event from another list where a value has been updated, during design time, it is not possible.

Through SharePoint Object Programming, we can custom program the things we need, what things to update after an event has been triggered, and all.


For custom programming in VS.NET, we need to extend the VS Extension for SharePoint, then the following steps to be done:

  1. Create a New Class Library Project and name it.
  2. Refer the Microsoft.Sharepoint.dll in this project.
  3. Inherit the SPItemEventReceiver class to receive the events from the specified list events.
  4. Override the different events inside the inherited class to do custom update.
  5. Create a StrongNameKey .snk file for the authentication in the properties of the project.
  6. Create a new Console project to specify the SPSite where the lists are located.
  7. Specify the SPEventReceiverType to the SPList of the above site.
  8. First Build the Class Library Project and copy the .dll file to the C:\Windows\Assembly folder.
  9. Set the Console project as the StartUp Project.
  10. Run the Console project by pressing F5.
  11. Reset IIS by executing 'iisreset' in the Run command to make the changes reflected in the actual SPSite.
  12. Go to the SharePoint Server WSS/MOSS to see the update.

Using the Code

Following is the Class Library Project where you have to have these:

  • SPSite - SharePoint Site or Web Site
  • SPList - SharePoint List or Table View
  • SPListItem - SharePoint ListItem or field of the List
  • SPQuery - SharePoint Query to embed the CAML Queries
  • CAML - Collaborative Markup Language
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Windows.Forms;

namespace twolists
public class Class1:SPItemEventReceiver
    public override void ItemAdded(SPItemEventProperties properties)

    void upd_bks_status(SPItemEventProperties properties)
        SPListItem acListItem = properties.ListItem;
        string lkbkid=acListItem["lkBooksAvail"].ToString();

        lkbkid= lkbkid.Substring(lkbkid.IndexOf('#') + 1);
        SPSite st = new SPSite("http://win2003/physlib");
        SPWeb wb=st.OpenWeb();
        SPList bklst=wb.Lists["Books"];
        SPQuery qry = new SPQuery();

        qry.Query = "<Where><Eq><FieldRef " + 
            "Name='Title'/><Value Type='Text'>" + 
            lkbkid + "</Value></Eq></Where>";
        SPListItemCollection itlst = bklst.GetItems(qry);
        SPListItem updList = itlst[0];
        updList["Status"] = "Taken";
        acListItem["Issue Status"] = lkbkid+" Issued Successfully";

Following is the Console Application where you do these:

  1. Build the Class Library Project and get the .dll and copy it to the Windows assembly folder.
  2. Reflect that assembly file name in this code.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace twolistsConsole
class Program
    static void Main(string[] args)
        SPSite st = new SPSite(@"http://win2003/physlib");
        SPWeb wb = st.OpenWeb();
        SPList ls = wb.Lists["Transactions"];

        //SPList rs = wb.Lists["Return Books"];
        string asmnam = "twolists,Version=," + 
        string clsnam = "twolists.Class1";
        ls.EventReceivers.Add(SPEventReceiverType.ItemAdded, asmnam, clsnam);
        //rs.EventReceivers.Add(SPEventReceiverType.ItemAdded, asmnam, clsnam);
  1. Run the Console project and reset IIS.
  2. Go to the SharePoint Site to see the update.

Happy programming..


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...


Comments and Discussions

GeneralWorking with SharePoint list Pin
labshasan22-May-11 1:40
memberlabshasan22-May-11 1:40 
GeneralWorking with two or more Sharepoint Lists Pin
Riazul Islam Mazumder5-Aug-09 2:23
memberRiazul Islam Mazumder5-Aug-09 2:23 
Generaldebug Pin
joekey9-Apr-09 12:17
memberjoekey9-Apr-09 12:17 
GeneralSubsites Pin
Anoosh Rahman4-Nov-08 2:11
memberAnoosh Rahman4-Nov-08 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 24 Oct 2008
Article Copyright 2008 by Sivsakthi.vijay
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid