locked
Using Custom List to perform some extra functions RRS feed

  • Question

  • Dear Friends

    I have a custom list and i want to perform

    1. I want to perform some programmatic functions ON SUBMIT new item call. I dont wanna interrupt sharepoint script on submit which adds data to the sharepoint database. But i want to add some extra activities too. Like adding data to my own Database. I just need to run my Script without interrupting Sharepoint's script.

    2. I want to get Items from My Database for 'Choice (menu to chose from)' Column in the list.

    I want it to be done in C#

    How can i do that. I dont know if it is possible or not.

    Please help

    Regards


    SharePoint 2007 (Administration/Development) Web developer and .NET DTS Programmer .NET Framework 2.0/3.5 SQL Server 2008/2005/2k
    Tuesday, July 27, 2010 6:39 AM

Answers

All replies

  • Hi,

        You can attach an event handler to your sharepoint list. Now , on ItemAdded event , you can write code in C# which can perform activities like adding data to your custom DB, getting items from custom DB etc.

    Yo can refer MSDN to create and add eventhandler to sharepoint list.

    Regards,

     

     


    Manvir
    Tuesday, July 27, 2010 7:32 AM
  • Dear Ali,

    Manvir is right, you should use Event Receivers in particular itemAdded event of your custom list to do your custom tasks when an item is saved on list. Please follow this thread to find out more about Event Handlers and how you can implement them on your list actions like submit and update etc.
    http://blogs.msdn.com/b/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx

    However, as far your second requirement goes, to get data on sharepoint list from external DB well that is not that straight forward. Please follow these threads that will give you more insight into it
    http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/048aeec7-f277-47b0-8daf-92b8763c2f16
    http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/75e3d3f9-6640-46c9-90c3-4c96c8a49948

    It looks like you might have to import the particular choices you want on your custom list to another list on same site collection and use this list column as a lookup to give you your choices on your custom list. So, you end up having two lists one which has items from DB and the other which uses the lookup column from this list. Unless you find a better work around.

    Hope this helps you and gives you a good starting point for further investigation.

    Thanks

    • Marked as answer by aliusman Tuesday, July 27, 2010 10:40 AM
    Tuesday, July 27, 2010 9:51 AM
  • Thank you guys, Thank you .Net Frenzy for details

    cheers


    SharePoint 2007 (Administration/Development) Web developer and .NET DTS Programmer .NET Framework 2.0/3.5 SQL Server 2008/2005/2k
    Tuesday, July 27, 2010 10:41 AM
  • Yes it can be done using features by registering event handlers to the list events as mentioned in previous posts.

    To register an event handler for list events, create a folder in \Template\Features to contain a Feature.xml file that specifies the scope and ID of the Feature, and an elements manifest file that the former file references.

    The element file would essentially contain a Receivers element which will point to the c# code you have written in the cs file.

    Tuesday, July 27, 2010 10:42 AM
  • Please and I mean please don't do it like mentioned by Farhan, keep it simple. (nothing against Farhan's approach, but it is worth sharing how VS takes care of all this)

    Open Visual Studio 05/08 and start a event receiver type project (you might need Sharepoint extensions for your visual studio if you dont have it find them here http://www.microsoft.com/downloads/details.aspx?familyid=7bf65b28-06e2-4e87-9bad-086e32185e68&displaylang=en), you will get all the events you need there. Uncomment your itemAdded event and change properties of your project to point to the sharepoint site url you want (from project in menu bar - properties last option - debug - start url browser with). Right Click project and hit deploy and everything is done for you. No need for doing XML chunk manually which causes issues if you don't know what you are doing. So all you have to do is write code and put more effort on getting your logics right than to attach features manually (coz elements, feature etc is all taken care of), visual studio should do it for you if you follow this way.

    Thanks,

    Tuesday, July 27, 2010 11:24 AM