Around Sharepoint 2013 " spchange" a Brief introduction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.