locked
When should I dispose SPWeb and SPSite objects? RRS feed

  • Question

  • When should I dispose SPWeb and SPSite objects and When would I use an event receiver for sharepoint?

    Ahsan Kabir

    Tuesday, July 17, 2012 6:06 PM

Answers

  • dispose spweb and spsite if you are not referring to the SPcontext

    SPsite site = new Spsite("yourURL") < this should be disposed

    spsite site = spcontext.current.site < this should not be disposed.

    Event Receiver. IF you want to automatically do something based on SharePoint events. i.e on item creation you want to copy the newly created item into another list. you can do the action by adding codes into the ItemAdded Event.

    Let me know if this helps



    • Edited by Ranjoe Tuesday, July 17, 2012 6:12 PM
    • Proposed as answer by GoingForward Tuesday, July 17, 2012 6:17 PM
    • Marked as answer by Pengyu Zhao Thursday, July 26, 2012 5:54 AM
    Tuesday, July 17, 2012 6:11 PM