// This function contains the logic for rendereing the three most recent posts
        private void LoadPosts()
        {
            try
            {
                // The SocialFeedManager class is what will enable us to work with feeds, posts, replies, and so on.
                SPSocial.SocialFeedManager feedMngr;
                feedMngr = new SPSocial.SocialFeedManager(clientContext);

                // Clear any current tiles from the UI.
                TimelinePanel.Controls.Clear();

                // psotIds is a List variable that will contain the IDs for up to three of the most resent posts.
                // It's used if the user chooses to 'Reply All', so we need to clear it here and then repopulate it
                // everytime we refresh the UI.
                postIds.Clear();

                // Create an SocialFeedOptions object that we will use when we retrieve a feed.
                // Note that we are only retrieving the three most recent posts, simply so that
                // they will fit in our UI.
                SPSocial.SocialFeedOptions feedOptions = new SPSocial.SocialFeedOptions();
                feedOptions.MaxThreadCount = 3;
                feedOptions.SortOrder = SPSocial.SocialFeedSortOrder.ByCreatedTime;

                // Now we can use the SocialFeedOptions to get the timeline feed for the current user
                SP.ClientResult<SPSocial.SocialFeed> timelineFeed = feedMngr.GetFeed(SPSocial.SocialFeedType.Timeline, feedOptions);

                // Load the feedMngr object and execute the previously-batched statements.

                clientContext.Load(feedMngr);
                clientContext.ExecuteQuery();

                // The value of the timelineFeed object is a ClientResult<SocialFeed>
                // so the first thing we'll do is cast it as an actual SocialFeed object
                SPSocial.SocialFeed feed = (SPSocial.SocialFeed)(timelineFeed.Value);

                // Then we'll iterate through the thread in the feed and obtain useful properties
                // for display in our tiles.
                foreach (SPSocial.SocialThread thread in feed.Threads)
                {
                    SPSocial.SocialActor[] actors = thread.Actors;
                    SPSocial.SocialPost post = thread.RootPost;
                    string authorName = actors[post.AuthorIndex].Name;
                    string postContent = post.Text;
                    int totalReplies = thread.TotalReplyCount;
                    Panel threadTile = new Panel();
                    threadTile.CssClass = "tile tileOrange fl";
                    threadTile.Controls.Add(new LiteralControl(authorName
                        + "<br/>("
                        + totalReplies.ToString()
                        + " replies)"));
                    Panel threadBody = new Panel();
                    threadBody.CssClass = "tileBody";
                    threadBody.Controls.Add(new LiteralControl(postContent));
                    threadTile.Controls.Add(threadBody);

                    // Show the two most recent replies in the tile, if there are any.
                    // Note: By default, only the two most recent replies are returned.
                    // To get all replies, you could call the SocialFeedManager.GetFullThread
                    // method before you load it and execute it.
                    if (totalReplies > 0)
                    {
                        SPSocial.SocialPost[] replies = thread.Replies;
                        foreach (SPSocial.SocialPost reply in replies)
                        {
                            Panel threadReply = new Panel();
                            threadReply.CssClass = "tileBody noPad";
                            threadReply.Style.Add("margin-left", "20px");
                            threadReply.Controls.Add(new LiteralControl(reply.Text));
                            threadTile.Controls.Add(threadReply);
                        }
                    }
                    TimelinePanel.Controls.Add(threadTile);

                    // Add the post IDs to the List object. This will be used if the user chooses to 'Reply All'
                    postIds.Add(post.Id);

                }
            }
            catch (Exception ex)
            {
                errLabel.Text = ex.Message;
            }
        }
        // This function contains the logic for rendereing the three most recent posts
        private void LoadPosts()
        {
            try
            {
                // The SocialFeedManager class is what will enable us to work with feeds, posts, replies, and so on.
                SPSocial.SocialFeedManager feedMngr;
                feedMngr = new SPSocial.SocialFeedManager(clientContext);

                // Clear any current tiles from the UI.
                TimelinePanel.Controls.Clear();

                // psotIds is a List variable that will contain the IDs for up to three of the most resent posts.
                // It's used if the user chooses to 'Reply All', so we need to clear it here and then repopulate it
                // everytime we refresh the UI.
                postIds.Clear();

                // Create an SocialFeedOptions object that we will use when we retrieve a feed.
                // Note that we are only retrieving the three most recent posts, simply so that
                // they will fit in our UI.
                SPSocial.SocialFeedOptions feedOptions = new SPSocial.SocialFeedOptions();
                feedOptions.MaxThreadCount = 3;
                feedOptions.SortOrder      = SPSocial.SocialFeedSortOrder.ByCreatedTime;

                // Now we can use the SocialFeedOptions to get the timeline feed for the current user
                SP.ClientResult <SPSocial.SocialFeed> timelineFeed = feedMngr.GetFeed(SPSocial.SocialFeedType.Timeline, feedOptions);


                // Load the feedMngr object and execute the previously-batched statements.

                clientContext.Load(feedMngr);
                clientContext.ExecuteQuery();

                // The value of the timelineFeed object is a ClientResult<SocialFeed>
                // so the first thing we'll do is cast it as an actual SocialFeed object
                SPSocial.SocialFeed feed = (SPSocial.SocialFeed)(timelineFeed.Value);

                // Then we'll iterate through the thread in the feed and obtain useful properties
                // for display in our tiles.
                foreach (SPSocial.SocialThread thread in feed.Threads)
                {
                    SPSocial.SocialActor[] actors = thread.Actors;
                    SPSocial.SocialPost    post   = thread.RootPost;
                    string authorName             = actors[post.AuthorIndex].Name;
                    string postContent            = post.Text;
                    int    totalReplies           = thread.TotalReplyCount;
                    Panel  threadTile             = new Panel();
                    threadTile.CssClass = "tile tileOrange fl";
                    threadTile.Controls.Add(new LiteralControl(authorName
                                                               + "<br/>("
                                                               + totalReplies.ToString()
                                                               + " replies)"));
                    Panel threadBody = new Panel();
                    threadBody.CssClass = "tileBody";
                    threadBody.Controls.Add(new LiteralControl(postContent));
                    threadTile.Controls.Add(threadBody);

                    // Show the two most recent replies in the tile, if there are any.
                    // Note: By default, only the two most recent replies are returned.
                    // To get all replies, you could call the SocialFeedManager.GetFullThread
                    // method before you load it and execute it.
                    if (totalReplies > 0)
                    {
                        SPSocial.SocialPost[] replies = thread.Replies;
                        foreach (SPSocial.SocialPost reply in replies)
                        {
                            Panel threadReply = new Panel();
                            threadReply.CssClass = "tileBody noPad";
                            threadReply.Style.Add("margin-left", "20px");
                            threadReply.Controls.Add(new LiteralControl(reply.Text));
                            threadTile.Controls.Add(threadReply);
                        }
                    }
                    TimelinePanel.Controls.Add(threadTile);

                    // Add the post IDs to the List object. This will be used if the user chooses to 'Reply All'
                    postIds.Add(post.Id);
                }
            }
            catch (Exception ex)
            {
                errLabel.Text = ex.Message;
            }
        }