SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL
SharePoint, Office 365, Azure, and Front end JS geek. – Chicago IL

Social

Post to Newsfeed on behalf of another user (Server Object Model)

The below code will post to Newsfeed for any user account you specify.   Activity appears the same as if the user manually posted.   This could be helpful for populating Newsfeed from external activity, custom event receivers, workflow, and other developer sources.   Enjoy! 

shades_smile

 

Screenshot

image

 

Code

 

References

How to Follow a site URL with PowerShell in SharePoint 2013

Background

While migrating from SharePoint 2010 to 2013 we needed to take MyLinks and replace with new Social Site Following.   Given a CSV with user names and site URLs I researched PowerShell options for programmatically making users follow sites.   Now we can pre-populate Follow Sites before launch.   The below code did the trick. 

shades_smile

 

Code

 

Screenshots

image
image

References

Support

If the target user does not yet have a MySite created you could see the below error.  The fix is simply to have them visit MySite – or – to upgrade their site collection from 2010 to 2013.

Exception calling “Follow” with “1” argument(s): “No personal site exists for the current user, and no further information is available. Internal type name: Microsoft.Office.Server.UserProfiles.SocialDataStoreException. Internal error code: 1.”

Note Board–Comment on external sites

While reviewing the new social features I noticed this interesting hyperlink on the “My Profile” page.   It allows users to bookmark a special link which they can use to extend “I like It” and “Tags & Notes” features beyond SharePoint to comment on external websites.

I was curious to look under the hood and understand how this could be done technically.

A complete JavaScript function is added to your bookmark in the URL field and executes when clicked.   The browser context holds the external site’s detail and is passed to SharePoint as GET parameter in the URL.   There is a safety check for SharePoint sites.   If the dialog function exists (CORE.JS) then we can assume we are on a SharePoint page and display the dialog instead of a full page.

The special character escaping is very clever and gives us a single line of text which JavaScript can execute.

 

image
image

ORIGINAL

SPACED FOR EASY READING

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲