RSS feeds have become indispensable and an effective tool for informing the target audience about relevant news. Therefore, it’s not surprising that many SharePoint users also want to include an RSS feed on their pages. This is not difficult for group-enabled team sites on modern pages. Because there is an RSS viewer web part, which is very easy to use. The situation is different with communication sites, which are still missing such a feature. We have therefore come up with a straightforward solution for integrating RSS feeds into SharePoint communication sites.

Integrate RSS feeds into SharePoint communication sites with PowerShell

The request for this came from one of our customers who bought a personalized press review from the Austria Press Agency. This provides the customer with a link with an RSS feed tailored to their needs. As with the web part for team sites, the link containing the RSS feed is to be read and processed so that the news it contains is displayed in a list on the start page. We were (and still are) very surprised that Microsoft has not yet introduced a standard feature here. But that’s what Smarter Business Solutions is here for! 😀 A major advantage of our solution is that you can “moderate” the news, and in this case the selection of the APA, via an approval workflow. Unfortunately, this is not the case with the RSS web part, as all the posts in the feed are displayed here unfiltered.

We implemented our solution for integrating an RSS feed into SharePoint communication sites in a fairly simple script with PnP PowerShell.

The process

  1. Read the contents of the RSS feed via REST
  2. Parsing the desired information from the RSS feed
  3. Save found images to a new folder in SharePoint
  4. Create and publish a new page with the information for each item in the RSS feed

Reading and parsing the RSS feed

In order to integrate an RSS feed into SharePoint communication sites, we must first read it out. To do this, we need the URL to the RSS feed, which we call with Invoke-RestMethod. Here we get the entire content as an array of XML elements:

 

$rssFeed = Invoke-RestMethod -Uri $rssFeedUrl

These XML elements represent the individual messages. So in the next step we go through every message (item) and get the following information:

  • Author
  • Guid
  • ItemOrigin (Url to news post)
  • Content
  • Publish date

We would like to note here that the item nodes of some RSS feeds have different sub-nodes and therefore the parsing must be developed individually.

 

$authorPrefix = $rssFeedItem.author
$title = $rssFeedItem.title
$guid = $rssFeedItem.guid
$sourceUrl = $rssFeedItem.itemOrigin
$content = $rssFeedItem.encoded.'#cdata-section'
$publishedDate = [datetime]::Parse($rssFeedItem.datetime)

 

Since posts can also contain images or other media and, as for our RSS feeds in SharePoint communication websites we also need a post image, we also have to parse these. To do this, we save the news page as HTML and search for the metatag property og:image. Its content attribute contains the link to the post image, which we will need later to display our SharePoint news.

In our case, the feed contains not only links to online articles but also links to PDF files. Here the approach via the metatags does not work, but we can easily get the information we need from the RSS feed item itself:

 

if($sourceUrl) {
	$result = Invoke-RestMethod -Uri $sourceUrl
	$html = New-Object -ComObject "HTMLFile"
	$html.IHTMLDocument2_write($result)

	$htmlTag = $html.childNodes | Where-Object {$_.nodename -like 'HTML'} 
	$headTag = $htmlTag.childNodes | Where-Object {$_.nodename -like 'HEAD'}
	$metaTags = $headTag.childNodes | Where-Object {$_.nodename -like 'META'}
				
	$ogimageUrl = $MetaTags | Where-Object { $_.outerHTML -like '*property="og:image"*' } | Select-Object -ExpandProperty content
}
else {
	if($rssFeedItem.content.thumbnail.count -gt 1) {
		$ogImageUrl = $rssFeedItem.content.thumbnail[0].url
	}
	else {
		$ogImageUrl = $rssFeedItem.content.thumbnail.url
	}

	$sourceUrl = $rssFeedItem.enclosure.url
}

Creating messages and including the RSS feed in the SharePoint communication site

In this step, we create a folder under the SiteAssets for each article and upload the found image there. If no picture has been found, we will take a suitable replacement image.

As the last step, we create the page for our news by creating a SitePage with the LayoutType Article and the previously extracted information. Finally, we’ll publish the page so that all other users can see it.

And here we already have our RSS feed on the SharePoint communication site:

Speaking of news, learn how we’ve implemented how to display important messages in SharePoint modern pages.

Have we sparked your interest?

We are happy to provide you with the complete script – leave us a comment or write to us!

Do you have any questions about including RSS feeds in SharePoint communication sites or a similar request? Then don’t hesitate and get in touch with us!

Contact us