Event receiver to iterate folder

Waylon: 2 weeks ago

I want to be able to set all items within a sharepoint folder when someone edit the metadata of any document in the library. The code below partially works but it only sets the item being updated and not all the items as i want. I'm only using the setting code to check it the for-next loop works, in reality I want to test a column status only.

 public override void ItemUpdated(SPItemEventProperties properties)
       SPListItem myItem = properties.ListItem;

       SPFolder folder = myItem.File.ParentFolder;

       //Query the List for all the item but query only the parent Folder
       SPQuery query = new SPQuery();
       query.Folder = folder;

       //Get the list Items and then Loop.
       SPListItemCollection ListItems = properties.List.GetItems(query);

       foreach (SPListItem item in ListItems)

               properties.ListItem["return"] = "set by event reciever";


Emily: 2 weeks ago

The code within the foreach is wrong. You are setting always the same item. Change it to:

foreach (SPListItem item in ListItems)
    item["return"] = "set by event reciever";