Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)

share|improve this question
add comment

1 Answer 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.

share|improve this answer
    
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 Dec 8 '11 at 16:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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