Remove an item of work from an event receiver width SPWorkItemJobDefinition class

Traitée Remove an item of work from an event receiver width SPWorkItemJobDefinition class

  • Saturday, May 05, 2012 7:27 AM
     
      Has Code

    I'm doing some testing with this part and I managed to get the SPWorkItemCollection to cycle through all the workitems who are drntro SPWorkItemCollection, my problem is that it is in the SPWorkItemCollection and poasa by the workitem in the foreach and do not know why. adjuto my códogo spero can check it out and somehow know if I'm doing something wrong:

    SPContentDatabase contentDB = site.ContentDatabase; Guid iGuid = new Guid("1549D631-2711-464D-8FD6-CD643F0B44A7"); SPWorkItemCollection iCollection = new SPWorkItemCollection(contentDB, iGuid);

    Until everything is in order here, but when you return to ICollection in to get the workitemgets out and no longer does the foreach prceso

    foreach (SPWorkItem workitem in iCollection) { if (workitem.ItemId == itemId) { iCollection.SubCollection(site, web, 0, (uint)iCollection.Count).DeleteWorkItem(workitem.Id); } }

     My requirement is that a workitem should not be presented twice in case the user iswrong, I'm working with a ItemUpdated receptors and the only way is to delete all itemsrelating to the current work and then create a new one.

    Greetings and thanks for your support

All Replies

  • Saturday, May 05, 2012 10:45 AM
     
     Answered
    You cannot delete items in the collection while iterating them. A simple workaround is to add the ID to a List<int> array and then after looping through them delete all items in that List<int> array.

    Microsoft Certified Architect - SharePoint 2010, Microsoft Certified Master - SharePoint 2010, SharePoint MVP and Solutions Architect
    http://www.wictorwilen.se/
    Author of SharePoint 2010 Web Parts in Action

  • Saturday, May 05, 2012 1:05 PM
     
      Has Code

    an apologydid not understandvery well whatecesitodo will bemuch troubleifyou sendmean exampleplease?

    I have notimeto programmingmuhoand apparentlynecesitdo that?

    List<int> Item = new List<int>();

    whatwould not knowhow to doisloopiterationorcometsmewith this list.

    thank you very much for your help