Office 365 Delve Blog Monitoring Tool

As my current client is trying to migrate to Office 365 environment from SharePoint 2013 on-premise, one of the issues is controlling the Delve personal blog.  As of now, there is no option to turn off the personal blog creation on Office 365.  So, the client wants to find way to monitor it.  That way they can at least know if there are any content they need to be aware and handled.

As you might already aware that there is really no way to do any customization on Delve (at least I can't find any way).  So I couldn't find any way to do any real time monitor with remote event receiver or something like that.

However, I did find a way to do a schedule monitor with console application.  After doing some research on google, I found this blog (https://en.share-gate.com/blog/office-365-delve-blogs-explained) that explains how the Delve blog works.

In summary, the Delve blog posts are save into a personal site collection in Pages library and they are based on Story Page content (that inherited the ContentTypeId:0x010100DA3A7E6E3DB34DFF8FDEDE1F4EBAF95D).

Knowing this information, I created a windows app to utilize SharePoint search.  With this app, I can get a list of keywords from SharePoint list that I can use for search.  The search will return me a list of blogs that contains any of filtered keywords.  To make it a scheduled monitoring, you can use the code below and create a console app.  Since it's based on search and SPO only do incremental search every 4 to 6 hours, the scheduled should probably be every 6 hours or daily.

In the windows app, I have the following code for the button click.

using (ClientContext clientContext = new ClientContext(txtSiteUrl.Text))
                {
                    SecureString passWord = new SecureString();
                    foreach (char c in txtPassword.Text.ToCharArray()) passWord.AppendChar(c);

                    clientContext.Credentials = new SharePointOnlineCredentials("richard@xxxx.com", passWord);
                    searchDelveBlogs(clientContext);

                    MessageBox.Show("Done");

                }

And the helper method is

private void searchDelveBlogs(ClientContext clientContext)
        {
            //loading all keywords (saved in a SharePoint list) used for filtering
            List keywordsList = clientContext.Web.Lists.GetByTitle("Filter Keywords");
            ListItemCollection keywords = keywordsList.GetItems(CamlQuery.CreateAllItemsQuery());
            clientContext.Load(keywords);
            clientContext.ExecuteQuery();

            //building query string with keywords
            string keywordString = string.Empty;
            foreach(var keywordItem in keywords)
            {
                string title = keywordItem["Title"].ToString();

                //put keyword in quote if there are spaces
                if (title.Contains(" "))
                {
                    title = string.Format("\"{0}\"", title);
                }

                //add to keyword string
                if (string.IsNullOrEmpty(keywordString))
                {
                    keywordString = title;
                }
                else
                {
                    keywordString += string.Format(" OR {0}", title);
                }
            }

            //Add AND to the keyword string so it can work with the Story Page content type ID
            if (!string.IsNullOrEmpty(keywordString))
            {
                keywordString = string.Format(" AND ({0})", keywordString);
            }

            KeywordQuery keywordQuery = new KeywordQuery(clientContext);
            keywordQuery.QueryText = string.Format("ContentTypeId:\"0x010100DA3A7E6E3DB34DFF8FDEDE1F4EBAF95D*\"{0}", keywordString);

            keywordQuery.SelectProperties.Add("Title");
            keywordQuery.SelectProperties.Add("Author");
            keywordQuery.SelectProperties.Add("Created");
            keywordQuery.SelectProperties.Add("DefaultEncodingUrl");
            keywordQuery.SelectProperties.Add("Path");
            keywordQuery.SelectProperties.Add("ID");
            keywordQuery.HitHighlightedProperties.Add("Title");

            SearchExecutor searchExecutor = new SearchExecutor(clientContext);
            ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
            clientContext.ExecuteQuery();

            Console.WriteLine("There are {0} results", results.Value[0].ResultRows.Count());
            foreach (var resultRow in results.Value[0].ResultRows)
            {
                DateTime lastModifiedTime = (DateTime)resultRow["LastModifiedTime"];

                Console.WriteLine("{0}: contains filtered words (modified: {1} by {2}): {3}", resultRow["Title"], lastModifiedTime.ToLocalTime(), resultRow["Author"], resultRow["HitHighlightedSummary"]);
            }

        }



Comments

Migration to SharePoint Online or Office365 plays a key role in the organizational modernization as by empowering workforces to enhance productivity.
Migration to SharePoint Online

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

SharePoint 2013 Features Information List