In some cases, you may need to extract some data from the article/blog list in SharePoint Online. In this tutorial, I will outline steps an admin user can take if they needed to see all of the users which liked and commented on an article post. Currently, when you hover over likes it will display a shortlist. If you needed the entire list, you would need to use a custom approach.
The strategy we used below is a sandbox solution with a visual web part in it. We created the “Generate List” button and when it is clicked, it cleans the “PostsInfomation” list (deleting all records).
To prevent a timeout, it clears the list and redirects to the same page with a “querystring” passing the last post id – in this case 0. When there is a “postid” “querystring” on the URL, the “Page_Load” method get this id and start looping through the posts list.
To retrieve the items, it is using (linq), with a lamba expression (item.Id > PostId). It loops up to 25 records (containing the information of who liked and commented on each article). On each loop, it gets the post id and retrieves all the likes and comments on that post.
A list is generated from this information. When the 25 records loop ends, it loops the generated list and creates the records on the PostsInfomation list.
This code is server-side (not CSOM) so it can run faster without having to request all records to the browser.
Follow the steps below:
1) Create a SharePoint Empty Project on a SharePoint 2013 foundation environment.
2) Select “Deploy as a sandboxed solution” to be able to install it on SharePoint Online.
3) Add a Visual Web Part to the solution.
4) Add a List Template to the solution to save the information generated by the code. To do this, add a new List to the project.
This option is to create a list from a new template to allow for the creation of columns.
5) Expand the newly created list on the visual studio solution; open the “listname”instance file.
Because this is a web part, the code is server-side.
7) This part of the code is to create a Web part configuration component. It renders like below and allows the user to enter the Blog Site Url.
8) To clear the Post Information list on the “Clear List” button, I use:
***If instead of clicking the “Clear List” button you click “Generate List,” it runs the code above, plus:
9) To redirect the page with a query string, “postid” with a 0.
10) After the postback, the code goes through the Page_Load method
Assuming the “postid” is 0:
- All of the buttons are disabled
- The progress bar becomes visible
- Call the “GenerateInBatched” method, with the Post Id as a parameter
11) “Posts” Lists are retrieved: