3

Is there a way, without additional programming, to get history of children related items to the parent one, for example:

SPList threads = SPContext.Current.Web.Lists["Blog threads"];
SPList posts = SPContext.Current.Web.Lists["Blog posts"];

posts have lookup field - threads, of course. Looking into the selected thread history I wish to know when a post was added it it, when was deleted or which changed.

I know I can iterate throug all items related:

SPList posts = SPContext.Current.Web.Lists["Blog posts"];
        SPQuery spQuery = new SPQuery();
        spQuery.Query =
            "<Where><Eq><FieldRef Name='Thread' LookupId='true' /><Value Type='Lookup'>" + threadId +
            "</Value></Eq></Where>";

        SPListItemCollection listItemCollection = posts.GetItems(spQuery);

        foreach (SPListItem spListItem in listItemCollection)
        {
            string historyUrl = "/_layouts/Versions.aspx?list={" + posts.ID + "}&ID=" + spListItem.ID";
            ...
        }

But I won't have info about deleted, changed items.

To summarize: I need a history of an item with all realated child items from other lists. (SharePoint 2010 if it matters)

1 Answer 1

1

If you have versioning enabled on the list you can access the versions of a SPListItem by the SPListItem.Versions property.

You could also use event receivers (SPItemEventReceiver) to track the changes and store the changes in another list.

1
  • Yes I know I can use EventReceivers and insert info to the third list, but as I've mentioned, I'm looking for a solution that will work for current items as well.
    – christof
    Commented Dec 8, 2011 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.