SharePoint 2013 Social API Customization
1.How to upload some image in newsfeed using Server Object Model
protected void Imageupload_Click(object sender, EventArgs e)
{
SPWeb currentWeb = SPContext.Current.Web;
SPUser currentUser = SPContext.Current.Web.CurrentUser;
SPUtility.ValidateFormDigest();
string accountName = @"domain\psno";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Get the UserProfil for target user
SPUser user = currentWeb.EnsureUser(accountName);
SPServiceContext serverContext = SPServiceContext.GetContext(currentWeb.Site);
UserProfileManager profileManager = new UserProfileManager(serverContext);
UserProfile profile = profileManager.GetUserProfile(currentUser.LoginName);
SPUserToken userToken = currentUser.UserToken;
SPSocialDataItem userMentionLink = new SPSocialDataItem
{
ItemType = SPSocialDataItemType.User,
AccountName = user.ToString()
};
//On the end, add an attachemt to the social post
string attachment = "http://10.11.1.70:9090/Documents/cartoon.jpg";
SPSocialAttachment statusAttachment = new SPSocialAttachment();
//Now, determine the attachment type. SharePoint will display on different ways videos, photos, and images attachments.
if (attachment.ToUpper().EndsWith("JPG") || attachment.ToUpper().EndsWith("JPEG") || attachment.ToUpper().EndsWith("PNG") || attachment.ToUpper().EndsWith("GIF"))
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Image;
}
else if (attachment.ToUpper().EndsWith("WMV") || attachment.ToUpper().EndsWith("MP4") || attachment.ToUpper().EndsWith("AVI") || attachment.ToUpper().EndsWith("MPEG"))
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Video;
}
else
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Document;
}
SPSocialPostCreationData postCreationData = new SPSocialPostCreationData();
statusAttachment.Uri = new Uri(attachment);
statusAttachment.Name = "My First Image Upload";
postCreationData.Attachment = statusAttachment;
if (profile != null)
{
SPSocialFeedManager _f = new SPSocialFeedManager(profile, serverContext, userToken);
_f.CreatePost(null, postCreationData);
TextBox1.Visible = false;
Button3.Visible = false;
Label1.Visible = true;
Label1.Text = "You wish has been posted succeessfully !!!";
}
});
}
Output of the above code :
How to do customization in newsfeed.This works for share point 2013.You can upload the image in document library
1.How to upload some image in newsfeed using Server Object Model
protected void Imageupload_Click(object sender, EventArgs e)
{
SPWeb currentWeb = SPContext.Current.Web;
SPUser currentUser = SPContext.Current.Web.CurrentUser;
SPUtility.ValidateFormDigest();
string accountName = @"domain\psno";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Get the UserProfil for target user
SPUser user = currentWeb.EnsureUser(accountName);
SPServiceContext serverContext = SPServiceContext.GetContext(currentWeb.Site);
UserProfileManager profileManager = new UserProfileManager(serverContext);
UserProfile profile = profileManager.GetUserProfile(currentUser.LoginName);
SPUserToken userToken = currentUser.UserToken;
SPSocialDataItem userMentionLink = new SPSocialDataItem
{
ItemType = SPSocialDataItemType.User,
AccountName = user.ToString()
};
//On the end, add an attachemt to the social post
string attachment = "http://10.11.1.70:9090/Documents/cartoon.jpg";
SPSocialAttachment statusAttachment = new SPSocialAttachment();
//Now, determine the attachment type. SharePoint will display on different ways videos, photos, and images attachments.
if (attachment.ToUpper().EndsWith("JPG") || attachment.ToUpper().EndsWith("JPEG") || attachment.ToUpper().EndsWith("PNG") || attachment.ToUpper().EndsWith("GIF"))
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Image;
}
else if (attachment.ToUpper().EndsWith("WMV") || attachment.ToUpper().EndsWith("MP4") || attachment.ToUpper().EndsWith("AVI") || attachment.ToUpper().EndsWith("MPEG"))
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Video;
}
else
{
statusAttachment.AttachmentKind = SPSocialAttachmentKind.Document;
}
SPSocialPostCreationData postCreationData = new SPSocialPostCreationData();
statusAttachment.Uri = new Uri(attachment);
statusAttachment.Name = "My First Image Upload";
postCreationData.Attachment = statusAttachment;
if (profile != null)
{
SPSocialFeedManager _f = new SPSocialFeedManager(profile, serverContext, userToken);
_f.CreatePost(null, postCreationData);
TextBox1.Visible = false;
Button3.Visible = false;
Label1.Visible = true;
Label1.Text = "You wish has been posted succeessfully !!!";
}
});
}
Output of the above code :
I am getting below error can you please help me out in this
ReplyDelete"Microsoft.Office.Server.Microfeed.MicrofeedException. Internal error code: 28."
your newsfeed is not configured correctly.Contact System Admin for this
Delete