Wednesday, November 7, 2018

Problem with rendering list RSS feed in Firefox

As you probably know Sharepoint allows to export list content into RSS format. There may be one issue however: some items may not be shown in Firefox default RSS viewer although these items exist in page source (i.e. returned from server). If you will check browser console you may find the following error there:

NS_ERROR_UNEXPECTED
SH_writeContent chrome://browser/content/feeds/subscribe.js:17:5
window.onload chrome://browser/content/feeds/subscribe.js:28:3

image

If we check RSS feeds where items are shown with RSS feeds where items are not shown we will find one difference – enclosure tag:

Working RSS:

<item>
  <title>Test</title>
  <link>http://example.com</link>
  <description></description>
  <author>...</author>
  <pubDate>...</pubDate>
  <guid isPermaLink="true">http://example.com</guid>
</item>

Non-working RSS:

<item>
  <title>Test</title>
  <link>http://example.com</link>
  <description></description>
  <author>...</author>
  <enclosure url="..." />
  <pubDate>...</pubDate>
  <guid isPermaLink="true">http://example.com</guid>
</item>

Items which are not rendered correctly have enclosure tag while items which are rendered correctly don’t have it.

In order to fix this issue you may use the following workaround for Sharepoint on-premise: create ashx handler, put it to /Layouts subfolder, code of the handler will send internal http request to OTB /_layouts/15/listfeed.aspx?List={listId} url, then remove enclosure tag via Regex and return final result to the response (i.e. implement kind of proxy for OTB RSS feed):

string url = string.Format("{0}?List={1}", SPUrlUtility.CombineUrl(web.Url, "_layouts/15/listfeed.aspx"), list.ID);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
	using (var stream = response.GetResponseStream())
	{
		using (var reader = new StreamReader(stream))
		{
			result = reader.ReadToEnd();
		}
	}
	result = Regex.Replace(result, @"<enclosure.+?/>", string.Empty);
}

As result there won’t be enclosure tag and RSS feed will be rendered correctly in Firefox.

1 comment:

  1. Hi,
    I had try in the iOS Mobile Safari, the content still cannot display

    ReplyDelete