همانطوری که قبلا نیز گفته شد ، قابلیت های اجتماعی ، بخش بزرگی از شیرپوینت 2013 می باشند. به وسیله آن کاربران می توانند محتویات ، سایت ها و حتی افراد را برای دستیابی به لیست بروز شده و تغییرات آنها در User’s MySite’s NewsFeed پی جویی کنند.
کارکرد این امکان برای مدیران سایت و سازمان که قصد دارند که هر بروز رسانی سند یا سایتی پی جویی شود ، بسیار مهم است. با معرفی این قابلیت ها در مورد شبکه های اجتماعی ، یک namespace جدید در Microsoft.Office.Server.Social نیز جهت تعامل با feed های اجتماعی و پی جویی افراد و محتوا از راهکار های شخصی شیرپوینت سرور 2013 و اپلیکیشن های شیرپوینت اضافه شده است.
در این پست ما نگاهی مختصر به نحوه برنامه نویسی برای پی جویی اسناد در شیرپوینت 2013 با استفاده از کلاس SPSocialFollowingManager می اندازیم. این کلاس بخشی از namespace جدید Microsoft Office Server Social می باشد. در این مثال ما دکمه ای بر روی Application شخصی که با استفاده از Visual Studio بکار گرفته شده است، اضافه کرده ایم. این دکمه Follow هنگامی که کلیک می شود ، کدی را اجرا خواهد کرد که بوسیله آن یک سند توسط کاربر در کتابخانه Shared Documents پی جویی می شود.
در این مثال ما برای پی جویی سند توسط کاربر از مدل Server Object استفاده کرده ایم.
کد زیر را جهت افزودن دکمه در وب پارت یا صفحه aspx اپلیکیشن ، کپی و paste کنید.
<asp:button runat="server" text="Follow" id="followBtn" />
همچنین کد زیر را در وب پارت و یا Code Behind صفحه اپلیکیشن تان کپی و paste کنید.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Social;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint.Portal.UserProfiles;
using Microsoft.SharePoint.Utilities;
//Adding the Button On click event
protected void Page_Load(object sender, EventArgs e)
{
followBtn.Click += new EventHandler(this.followBtn_Click);
}
//Adding the function to Follow the document
void followBtn_Click(Object sender,EventArgs e)
{
//Get the targeted user
SPWeb currentWeb = SPContext.Current.Web;
SPUser currentUser = SPContext.Current.Web.CurrentUser;
String _docToFollow = "/Shared%20Documents/Organization%20Rule%20Book.docx";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Get the UserProfil for target user
SPServiceContext serverContext = SPServiceContext.GetContext(currentWeb.Site);
UserProfileManager profileManager = new UserProfileManager(serverContext);
UserProfile profile = profileManager.GetUserProfile(currentUser.LoginName);
if (profile != null){
//Create a Social Manager profile
SPSocialFollowingManager _followManager = new SPSocialFollowingManager(profile);
//Create a Social actor with current web
SPSocialActorInfo newActor = new SPSocialActorInfo();
// this works, because the protocol is included in the string
Uri serverUri = new Uri(currentWeb.Url);
// needs UriKind arg, or UriFormatException is thrown
Uri relativeUri = new Uri(_docToFollow, UriKind.Relative);
newActor.ContentUri = new Uri(serverUri, relativeUri);
newActor.AccountName = currentUser.LoginName;
newActor.ActorType = SPSocialActorType.Document;
//Follow on this actor
_followManager.Follow(newActor);}
});
}
}
}
پس از اجرای این کد ، کاربر مد نظر پی جویی سند مطلوب را انجام خواهد داد.
پست مرتبط :
طراحی پرتالهای اینترنت و اینترانت
سامانه مدیریت پروژه سازمانیEPM