0

In this code im getting current users followed blog, (I got what are sites the user is following). I have to get the post list in this blog site collection. Tell me the approach to get the list.

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.Office.Server.Social;
using System.Data;
using System.Web.UI.WebControls;

namespace VisualWebPartProject1.VisualWebPart1
{
    [ToolboxItemAttribute(false)]
    public partial class VisualWebPart1 : WebPart
    {
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling using
        // the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
        public VisualWebPart1()
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }
        DataTable dt = new DataTable();



        protected void Page_Load(object sender, EventArgs e)
        {
            using (SPSite spSite = new SPSite("/sites/testBlog"))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {

                    dt.Columns.Add("URl",typeof(string));
                    SPUser currentuser = spWeb.CurrentUser;
                   SPServiceContext context = SPServiceContext.GetContext(spSite);
                   UserProfileManager upm = new UserProfileManager(context);
                   UserProfile profile = upm.GetUserProfile(currentuser.LoginName);

                   SPSocialFollowingManager followmanager = new SPSocialFollowingManager(profile);
                   followedsites = followmanager.GetFollowed(SPSocialActorTypes.Sites);


                   foreach (SPSocialActor actor in followedsites)
                   {                     

                       dt.Rows.Add(actor.ContentUri);

                     }


            GridView1.DataSource = dt;
            GridView1.DataBind();
            Controls.Add(GridView1);



                }
            }

        }  
        public SPSocialActor[] follwedsites { get; set; }

        public SPSocialActor[] followedsites { get; set; }
    }
}
  • 1
    SPList posts = spWeb.Lists["Posts"] ?? – Michael Colbs Jul 23 '14 at 14:48
1

Add function following function:

private SPList GetBlogList(string url)
{
    using (SPSite site = new Site(url)
    {
         using (SPWeb web = site.RootWeb)
         {
             return web.Lists["Posts"];
         }
    }
}

And then in your code, write,

SPList listBlog = GetBlogList(actor.ContentUri);

Hope this helps!!

0

You can easily access the list as

SPList posts = spWeb.Lists["Posts"] 
0
SPWeb.GetList (string strUrl) – Good 
using (SPSite site = new SPSite(strSite)) 
{ 
  using (SPWeb web = site.OpenWeb())
        { 
            SPList oList = web.GetList(http://Site/list/AllItem.aspx) 
        }
}

In this case, first retrieves the list GUID from the url (database hit), then it loads the metadata* for that specific list.

SPWeb.Lists (“name”) – Not Good 
using (SPSite site = new SPSite(strSite))
{ 
using (SPWeb web = site.OpenWeb())
       { 
          SPList oList = web.Lists ["MyList"] 
       }
}

In this case, it loads the metadata* of the all lists in that specific SPWeb object. Then it does SPList.Title comparison with metadata of all the lists returned and then it returns the matching list from the SPWeb.Lists collection.

0

In this dt.rows.add(actor.contenturi) im getting all the follwing sites.but i need to get subsites list.(post is a default list in all blog list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.