Friday, March 8, 2013

Push Newsfeed to Sharepoint 2013 Site From External Sources

SharePoint 2013 comes with a lot of new features especially for Social Networking. News Feed is one of those features. SharePoint 2010 also has that feature but External systems can't send external feeds to the SharePoint farm. SharePoint 2013 has defined some libraries (API) to push feeds from outside to SharePoint farm.
In addition to that there are some different between 2010 newsfeed and SharePoint 2013 Newsfeed.
 
Prerequisites

1. Configured SharePoint 2013 Farm  
2. MySiteHost URL or Team Site URL
3. Visual Studio 2012 installed in machine

Steps to create the Project to send Newsfeed to SharePoint My site or Team site


1. Create New Class library in Visual Studio 2012 and named it as "NewsFeedPushLib"


2. Create a file and named it as "NewsFeedPushClass.cs"

3. Add below dlls as reference to that project 


4. write the following code into that class.


a. Check for accessibility - Need to ensure that that user has enough rights to push feeds into share point site.
 
          System.Net.NetworkCredential cred = new System.Net.NetworkCredential("UserName", "Password");
          ClientContext clientContext = new ClientContext("siteURL");
          clientContext.Credentials = cred;


b. Get the thread owner from the PeopleManager object.

          Microsoft.SharePoint.Client.UserProfiles.PersonProperties owner = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(clientContext).GetPropertiesFor(
"UserName");
 

c. Get the MicrofeedManager object.

                MicrofeedManager microfeedManager = new MicrofeedManager(clientContext);


d. Register the requests that you want to run.
                // The first call requests only the DisplayName and AccountName
                // properties of the owner object.


                clientContext.Load(owner, o => o.DisplayName, o => o.AccountName);
                clientContext.Load(microfeedManager);


e. Run the requests on the server.
                clientContext.ExecuteQuery();


f. Define defenitionName

 MicrofeedPostOptions postOptions = new MicrofeedPostOptions();
postOptions.DefinitionName = "defenitionName";

Eg : "Microsoft.SharePoint.Microfeed.UserPost" for User Post  

g. Send the Feed

    if (!string.IsNullOrEmpty(feedItem))
     // remove the empty/Null feed                 

   {
         if (feedItem.Length > 512)
         {
               feedItem = feedItem.Substring(0, 508) + "...";
// to limit the feed limit
         }
         postOptions.Content = feedItem; 
// content for the feed 

         if ((!(feedItem == null)) && !(feedItem.Equals("")))
        {
            if (true)
            {
                postOptions.TargetActor = targetActor;
// set the target actor for a feed               
                microfeedManager.Post(postOptions); 
//post the feed on each user's newsfeed
                clientContext.ExecuteQuery();
                success = true;
            }
            else
            {
                success = false;
//couldn't push it to target no valid target
            }

        }
   }

}

5. Create another project (console Application) and create new file. then call Push newsfeed method in this class

 NewsFeedPushClass.PushToSharePoint("Testing Feed1", "Sharepoint_Web_application_URL", "domain\\user", "password", "Team Site URL", "Microsoft.SharePoint.Microfeed.UserPost");

6. Run the program and check whether it is working or not.



Sample feed(Defect Information) pushed from external system(Project management system) to Team Site

 
Download the Solution File - MediaFire Link
 
 

 

 

13 comments:

Ahamed Shaamil said...
This comment has been removed by the author.
Jrichview said...
This comment has been removed by the author.
Jrichview said...

I need to aggregate some external RSS feeds and display them on a page in a public web site hosted in SharePoint 2013 online (Office 365). Existing web parts do not seem to work in this scenario.

Your code seems to demonstrate how to push RSS feeds to sharepoint, which is similar. Any thoughts on how you would do it?

Surendran Kajaruban said...

In this post , i just push the string , but if you want you can push the RSS feed also . Change the feedItem according to your needs. It will work as you expect .

Anonymous said...

Is it possible to use OOB NewsFeed Control in a custom User Control(ascx) page?

Anonymous said...

ninest123 16.03
ray ban sunglasses, cheap oakley sunglasses, replica watches, michael kors outlet, oakley sunglasses, jordan shoes, prada handbags, nike outlet, nike air max, nike free, louis vuitton, tiffany and co, ugg boots, louboutin outlet, ray ban sunglasses, louis vuitton outlet, burberry outlet online, michael kors outlet, chanel handbags, uggs on sale, tiffany jewelry, louis vuitton outlet, michael kors outlet, oakley sunglasses, oakley sunglasses, louboutin shoes, prada outlet, ugg boots, ray ban sunglasses, ugg boots, burberry, replica watches, michael kors outlet, tory burch outlet, longchamp outlet, michael kors outlet, louis vuitton, michael kors, polo ralph lauren outlet, longchamp outlet, louis vuitton, polo ralph lauren outlet, louboutin, oakley sunglasses, gucci outlet, ugg boots, christian louboutin outlet, nike air max, longchamp

Anonymous said...

north face, hogan, coach outlet, air force, hollister pas cher, michael kors, coach outlet, lululemon, burberry, sac guess, nike roshe, nike free, true religion jeans, air jordan pas cher, lacoste pas cher, ralph lauren pas cher, michael kors, kate spade outlet, ralph lauren uk, michael kors, new balance pas cher, true religion jeans, ray ban uk, nike roshe run, converse pas cher, michael kors, hermes, mulberry, vans pas cher, louboutin pas cher, true religion outlet, ray ban pas cher, nike air max, oakley pas cher, air max, timberland, nike free run uk, kate spade handbags, nike air max, hollister, tn pas cher, replica handbags, nike air max, vanessa bruno, abercrombie and fitch, sac longchamp, true religion jeans, nike blazer, coach purses, longchamp pas cher, north face

Anonymous said...

ugg,uggs,uggs canada, canada goose, ugg,ugg australia,ugg italia, canada goose, hollister, wedding dresses, moncler, louis vuitton, canada goose outlet, swarovski, pandora charms, pandora jewelry, moncler outlet, moncler, sac louis vuitton pas cher, replica watches, louis vuitton, marc jacobs, louis vuitton, vans, moncler, swarovski crystal, pandora jewelry, toms shoes, moncler, juicy couture outlet, doudoune canada goose, karen millen, converse, lancel, canada goose outlet, coach outlet, gucci, ray ban, thomas sabo, moncler, supra shoes, canada goose uk, juicy couture outlet, links of london, barbour jackets, louis vuitton, canada goose, barbour, ugg boots uk, pandora charms, bottes ugg, converse outlet, moncler, montre pas cher, canada goose, ugg pas cher, moncler
ninest123 16.03

5689 said...

zzzzz2018.8.27
basket nike femme
pandora jewelry
cheap snapbacks
pandora outlet
salomon
basket nike
true religion outlet
canada goose jackets
ugg boots clearance
michael kors outlet online

5689 said...

ralph lauren uk
christian louboutin shoes
ferragamo outlet
canada goose jackets
polo ralph lauren
pandora
adidas superstar
christian louboutin outlet
skechers outlet
lacoste outlet
zzzzz2018.8.27

cctv camera dealer in Jaipur said...

Amazing!!!! Such a very nice blog, very interesting
cctv camera in Jaipur

Unknown said...

check my blogyou can find out more check my blogmoved here this contact formweblink

leeteson said...

article source see here Continued Visit Your URL see here now read the full info here