In SharePoint, we often need to get these change items, but the API provides us with Spchange objects. The following, in the adoption of our catalogue information this goal.
1, create the test list, the name is called "Spchangeitems". Instead, insert the test data, such as the following drawings:
2. Delete the data with ID 3 and change the data with ID 2 to prepare for our back test, for example:
3, write our code. In this case, there is a need to be able to encapsulate WebPart or application page in the console, for example:
4, the result of operation, for example:
We were able to see a record of the addition, update, and deletion data displayed in our dialog box, which is the application of Spchange, of course. This is not just for lists. can also operate the document library, pages and other, detailed to participate in the text attached to the MSDN link;
5. Attached source code
1SPList list = web. GetList ("Lists/spchangeitems");2 3Spchangequery query =NewSpchangequery (true,true);4Spchangecollection Changecoll =list. GetChanges (query);5 6 foreach(Spchange changeinchchangecoll)7 {8 if(change isSpchangeitem)9 {TenSpchangeitem Changeitem =(Spchangeitem) change; One A if(Changeitem. ChangeType = =spchangetype.delete) - { -Console.WriteLine (string. Format ("Listname:{0},itemid:{1}", List. Title, Changeitem. Id.tostring ())); theConsole.WriteLine (string. Format ("changetype:{0}", Changeitem. Changetype.tostring ())); - } - Else - { + Try - { +SPListItem item =list. GetItemByID (Changeitem. ID); AConsole.WriteLine (string. Format ("listname:{0},itemid:{1},title:{2}", List. Title, Changeitem. Id, item. Title)); atConsole.WriteLine (string. Format ("changetype:{0}", Changeitem. Changetype.tostring ())); - Console.WriteLine (); - } - Catch { } - } - } in}
Summary
Through Spchange we can query the website, view, user, list, directory, user group and so on changes, can be very convenient to understand the changes of the site. It is convenient to encapsulate it as a WebPart or Web application pages for presentation.
References link
Http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spchange (v=office.15). aspx
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Around Sharepoint 2013 " spchange" a Brief introduction