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
- Read the contents of the RSS feed via REST
- Parsing the desired information from the RSS feed
- Save found images to a new folder in SharePoint
- 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!
Please can I have access to full script
Hire them and they’ll provide it – it’s the whole point lol
Hey Paul. Thanks for your comment. We do indeed give away our script for free. We just want to show that the demand is there and that RSS feeds are also wanted by the community for communication sites. If you are interested in the script, let us know. ๐
Hello Guys,
please i would need the full script.
Thanks for helping out. Wondering why it is not part of communication sites webparts.
Can I have access to full script please ?
Good stuff. May I use the script?
This is a great solution to a problem that I’ve been looking for. I’d like to have the script if it is still available.
an I have access to full script please ? Thanks!
Great solution, please could I use the script
fantastic Idea! can i please use the script? Thanks
This is exactly what I have been looking for. Can you please share the script.
Thanks
Love the approach. Can I please get the script for this solution?
Cheers!
Hello, can I please get a copy of the complete script?
Thank you for this. May I use the script?
Love to see the full script!
Could definitely use this! Please share the script! Thanks!
I’d be really interested in this script to enhance my communication type site ๐
Hi. Can I please get a copy of the full script? Thank you.
Hello! Could I please have the full script.
Would love to have the full script!
I’d also love the full script
Sounds good.
May I have access to full script?
This is exactly what I’m looking for. Would you please send me the full script? Thanks!
Please can I have access to full script
May I please have access to the script?
May I have access to the full script?
can i have the full script plz
Hi!,
can I have access to full script please?
Hi, there. Could i please have the full script ๐
Can I get the full script please! ๐
Can I get a copy of the script please?
Would be amazing to get a copy of the full script
Hi, i am looking for this solution. Please help to provide the script.
Good day, can you share full code with me please
Hello, can you share full code with me please.
Hi there. I would also love to see your solution, could you send me a copy of the full script? Thanks so much.
Hi, there. Could i please have the full script ๐?