// Iterate through the items and get each item's display
        // name, content URI, and absolute URI.
        void IterateThroughContent(int count, SPSocialActor[] actors)
        {
            SPSocialActorType actorType = actors[0].ActorType;

            //Console.WriteLine("\nThe current user is following {0} {1}s:", count, actorType.ToString().ToLower());
            foreach (SPSocialActor actor in actors)
            {
                //Console.WriteLine("  - {0}", actor.Name);
                //Console.WriteLine("\tContent URI: {0}", actor.ContentUri);
                //Console.WriteLine("\tURI: {0}", actor.Uri);
            }
        }
        // Get the count of the items that the current user is following.
        void WriteFollowedCount(SPSocialActorType type)
        {
            // Set the parameter for the GetFollowedCount method, and
            // handle the case where the item is a site.
            SPSocialActorTypes types = SPSocialActorTypes.Documents;

            if (type != SPSocialActorType.Document)
            {
                types = SPSocialActorTypes.Sites;
            }

            int followedCount = followingManager.GetFollowedCount(types);

            des.Text = "关注的网站的个数:" + followedCount.ToString();
            //clientContext.ExecuteQuery();
            //Console.WriteLine("{0} followed {1}", followedCount.Value, types.ToString().ToLower());
        }
        //"以下代码示例使当前用户开始关注或停止关注某目标项目"
        void GuanZhuAndStopGuanZhu()
        {
            des.Text = "";
            // Replace the following placeholder values with the URL of the target
            // server and target document (or site).
            string            serverUrl   = txtSiteUrl.Text;
            string            contentUrl  = txtDocUrl.Text;
            SPSocialActorType contentType = SPSocialActorType.Site;

            //WriteFollowedCount(contentType);
            using (SPSite site = new SPSite(serverUrl))
            {
                using (new Microsoft.SharePoint.SPServiceContextScope(SPServiceContext.GetContext(site)))
                {
                    SPServiceContext   serviceContext = SPServiceContext.GetContext(site);
                    UserProfileManager upm            = new UserProfileManager(serviceContext);
                    ////Create user sample string sAccount = "mydomain\\myalias";
                    ////To set prop values on user profile
                    string accountName = SPContext.Current.Web.CurrentUser.LoginName;
                    accountName = accountName.Substring(accountName.LastIndexOf("|") + 1);
                    //if (accountName == "SHAREPOINT\\system")
                    //    accountName = "ccc\\xueqingxia";
                    ////UserProfile u = upm.GetUserProfile(accountName);
                    followingManager = new SPSocialFollowingManager();//u,serviceContext);

                    int followedCount = followingManager.GetFollowedCount(SPSocialActorTypes.Sites);
                    des.Text = "关注的网站的个数:" + followedCount.ToString();
                    // Create a SocialActorInfo object to represent the target item.
                    SPSocialActorInfo actorInfo = new SPSocialActorInfo();
                    actorInfo.ContentUri = new Uri(contentUrl);
                    actorInfo.ActorType  = contentType;
                    //actorInfo.AccountName = accountName;

                    // Find out whether the current user is following the target item.
                    bool isFollowed = followingManager.IsFollowed(actorInfo);
                    des.Text += " isFollowed:" + isFollowed.ToString();
                    try
                    {
                        //SPSocialFollowResult result = followingManager.Follow(actorInfo);
                        //// If the result is AlreadyFollowing, then stop following
                        //// the target item.
                        //des.Text += "FollowResult:" + result.ToString();
                        //if (result == SPSocialFollowResult.AlreadyFollowing)
                        //{
                        if (isFollowed)
                        {
                            des.Text += " StopFollowing: ";
                            bool isToped = followingManager.StopFollowing(actorInfo);
                            des.Text += isToped.ToString();
                        }
                        else
                        {
                            des.Text += " Follow: ";
                            SPSocialFollowResult result = followingManager.Follow(actorInfo);
                            // If the result is AlreadyFollowing, then stop following
                            // the target item.
                            des.Text += "FollowResult:" + result.ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        des.Text += ex.ToString();
                    }
                }
            }
        }