SharePoint How To: Gather Data from Article Posts and Blogs in SharePoint Online

Acrowire

SharePoint How To: Gather Data from Article Posts and Blogs in SharePoint Online

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. 

SharePoint How To_ 7.17 Image 1

 

 

 

2) Select “Deploy as a sandboxed solution” to be able to install it on SharePoint Online.

SharePoint How To_ 7.17 Image 2

 

 

 

3) Add a Visual Web Part to the solution.

SharePoint How To_ 7.17 Image 3

 

 

 

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.

SharePoint How To_ 7.17 Image 4

SharePoint How To_ 7.17 Image 5

 

 

 

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.

SharePoint How To_ 7.17 Image 66) Create and configure the columns.

SharePoint How To_ 7.17 Image 7

 

 

 

 

 

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.

SharePoint How To_ 7.17 Image 8

8)  To clear the Post Information list on the “Clear List” button, I use: 

SharePoint How To_ 7.17 Image 9

***If instead of clicking the “Clear List” button you click “Generate List,” it runs the code above, plus:

SharePoint How To_ 7.17 Image 10

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

SharePoint How To_ 7.17 Image 11.1

SharePoint How To_ 7.17 Image 11.2

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: 

SharePoint How To_ 7.17 Image 1212) And finally, it loops through all the Posts to complete this task. 

This entry was posted in Blog and tagged , , , . Bookmark the permalink.

Leave a Reply