Пример #1
0
        //当前用户正在关注的文档和网站
        private int[] GetFollowedCount()
        {
            int followedSiteCount = 0;
            int followedDocCount  = 0;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                        UserProfileManager upm          = new UserProfileManager(serviceContext);
                        string accountName = GetAccountName();
                        UserProfile u      = upm.GetUserProfile(accountName);

                        SPSocialFollowingManager followingManager = new SPSocialFollowingManager(u, serviceContext);
                        followedSiteCount = followingManager.GetFollowedCount(SPSocialActorTypes.Sites);
                        followedDocCount  = followingManager.GetFollowedCount(SPSocialActorTypes.Documents);
                    }
                });
            }
            catch
            {
            }
            return(new int[] { followedSiteCount, followedDocCount });
        }
Пример #2
0
        private void ClientGuanZhu()
        {
            SPSite             site           = SPContext.Current.Site;//(txtSiteUrl.Text))
            SPServiceContext   serviceContext = SPServiceContext.GetContext(site);
            UserProfileManager upm            = new UserProfileManager(serviceContext);
            string             accountName    = SPContext.Current.Web.CurrentUser.LoginName;

            accountName = accountName.Substring(accountName.LastIndexOf("|") + 1);
            des.Text    = "";
            if (accountName == "sharepoint\\system")
            {
                accountName = "ccc\\xueqingxia";
            }
            if (upm.UserExists(accountName))
            {
                UserProfile u = upm.GetUserProfile(accountName);
                Response.Write(u[PropertyConstants.PictureUrl].Value);
                SPSocialFollowingManager follow     = new SPSocialFollowingManager(u, serviceContext);
                SPSocialActorInfo        socialInfo = new SPSocialActorInfo();
                des.Text = follow.GetFollowedCount(SPSocialActorTypes.Sites).ToString();
                foreach (SPSocialActor spFollow in follow.GetFollowed(SPSocialActorTypes.Sites))
                {
                    //spFollow.Status = SPSocialStatusCode.InternalError;
                    socialInfo.ContentUri = spFollow.Uri;
                    //socialInfo.AccountName = u.AccountName;
                    socialInfo.ActorType = SPSocialActorType.Site;
                    follow.StopFollowing(socialInfo);
                    des.Text += "ok! ";
                }
            }
        }
Пример #3
0
        //以下代码示例获取当前用户正在关注的文档和网站并获取有关用户的关注内容状态的信息
        void GetGuanZhu()
        {
            // Replace the following placeholder values with the URLs of
            // the target server, document, and site.
            string serverUrl = txtSiteUrl.Text;
            //string docContentUrl =txtDocUrl.Text ;
            string siteContentUrl = txtDocUrl.Text;  // do not use a trailing '/' for a subsite

            // Get the client context.
            //ClientContext clientContext = new ClientContext(serverUrl);

            // Get the SocialFollowingManager instance.
            SPSocialFollowingManager followingManager = new SPSocialFollowingManager();

            // Create SocialActorInfo objects to represent the target
            // document and site.
            //SPSocialActorInfo docActorInfo = new SPSocialActorInfo();
            //docActorInfo.ContentUri = new Uri(docContentUrl);
            //docActorInfo.ActorType = SPSocialActorType.Site;
            SPSocialActorInfo siteActorInfo = new SPSocialActorInfo();

            siteActorInfo.ContentUri = new Uri(siteContentUrl);
            siteActorInfo.ActorType  = SPSocialActorType.Site;

            // Find out whether the current user is following the target
            // document and site.
            //ClientResult<bool> isDocFollowed = followingManager.IsFollowed(docActorInfo);
            bool isSiteFollowed = followingManager.IsFollowed(siteActorInfo);

            // Get the count of documents and sites that the current
            // user is following.
            //ClientResult<int> followedDocCount = followingManager.GetFollowedCount(SocialActorTypes.Documents);
            int followedSiteCount = followingManager.GetFollowedCount(SPSocialActorTypes.Sites);

            // Get the documents and the sites that the current user
            // is following.
            //ClientResult<SocialActor[]> followedDocResult = followingManager.GetFollowed(SocialActorTypes.Documents);
            SPSocialActor[] followedSiteResult = followingManager.GetFollowed(SPSocialActorTypes.Sites);

            // Get the information from the server.
            clientContext.ExecuteQuery();

            //// Write the results to the console window.
            //Console.WriteLine("Is the current user following the target document? {0}", isDocFollowed.Value);
            //Console.WriteLine("Is the current user following the target site? {0}", isSiteFollowed.Value);
            //if (followedDocCount.Value > 0)
            //{
            //    IterateThroughContent(followedDocCount.Value, followedDocResult.Value);
            //}
            if (followedSiteCount > 0)
            {
                IterateThroughContent(followedSiteCount, followedSiteResult);
            }
            Console.ReadKey();
        }
Пример #4
0
        // 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());
        }
Пример #5
0
        //"以下代码示例使当前用户开始关注或停止关注某目标项目"
        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();
                    }
                }
            }
        }