Dispose in event receivers RRS feed

  • Question

  • We are using SPListItem's ItemAdding Event.
    As per below link, we should not dispose SP objects in event receivers rather we should use SPItemEventProperties class.


    But In real world scenario, we come to case where we want to deal with different SPWeb object than mentioned by SPItemEventProperties.

    Hence we use following code in SPEvent receivers,is it Ok if we use it in this way?

     using (SPSite subsite = new SPSite(resWebUrl))//resWebUrl => URL for SPSite
                       using (SPWeb Resourssite = subsite.OpenWeb())
    //do my stuff here.

    Thanks in Advance...

    - Shwetank


    Tuesday, November 19, 2013 10:29 AM

All replies

  • HI,

    If this web is different from the web where the event accrued.Then no problem we have to go with this way.

    But if the web you are getting in same context then use SPItemEventProperties class.


    • Proposed as answer by VikashKummar Thursday, January 22, 2015 8:08 AM
    Tuesday, November 19, 2013 10:40 AM