Main Page
 The gatekeeper of reality is
 quantified imagination.

Stay notified when site changes by adding your email address:

Your Email:

Bookmark and Share
Email Notification
Project "Facebook Graph Feed"
    Purpose
Download the full source code for this example

The purpose of this page is to show you how to use ASP.NET (Visual Basic) in order to get wall posts (which need to be public or your "App" has permissions to) from Facebook, which is in JSON format, to ultimately show on your website. There are a variety of ways with which to process the JSON data. In this example, standard .NET classes (and nested, or classes inside of classes) will be used because they are very simple to work with. NOTE: This page assumes you are familar with the Graph API; if you are not please see the introduction.


Before continuing, I should mention that the JSON-response of wall posts does not include the URL to the profile picture of posters to a wall. In order to get the URL of the profile picture, you have two alternatives: (1) you can mash together the URL, which is a redirect that Facebook will route requests through, or, (2) you can actually capture the redirect (302) that Facebook generates to the actual profile picture URL. I prefer to minimize the number of hops that a client browser must perform so I put together a .NET function which captures the 302 redirect and the actual URL to the profile picture as shown below:
Public Class respURLResolver
Public Function resolve302(ByVal URL As String, ByVal crawlAgent As String, ByVal crawlMethod As String) As String
Dim resolveData As String = URL
Try
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(resolveData), HttpWebRequest)
myRequest.UserAgent = crawlAgent
myRequest.Method = crawlMethod
' .NET4 Specific Component
Dim capturedUri As New Uri(resolveData)
Dim myResponse As WebResponse = CType(myRequest.GetResponse(), WebResponse)
If capturedUri.Equals(myResponse.ResponseUri) Then
' Pointing to self
Else
' Pointing somewhere else
resolveData = myResponse.ResponseUri.ToString()
End If
myResponse.Close()
Catch ex As Exception
resolveData = "[ERROR 1] " & ex.Message.ToString()
End Try
Return (resolveData)
End Function
End Class


Creating Classes Matching JSON Data
The next step in the puzzle of getting wall posts, is figuring out how to use classes (in this example) with the deserialized JSON data (a standard .NET function). Ordinarily it is a snap to set up classes with JSON data in .NET under many circumstances...but Facebook wall posts are a bit more complicated than many places in JSON format because many things are nested and sub-nested. Let's take a look at some side-by-side examples of what a class looks like based on the JSON data:


(Enlarge)
  1. JSON elements which are not arrays need to be initialized.

(Enlarge)
  1. JSON elements which are arrays do not need to be initialized.

(Enlarge)
  1. JSON elements which contain arrays, but are not arrays themselves do not need to be initialized.

(Enlarge)
  1. In some cases, JSON elements will have names which are numbers or begin with a number; so those cannot be used...I'm not aware of any language which allows you to use a numeric value as the name of a class property or even name of a function/subroutine. Luckily there's very few that Facebook exposes and have minimal impact to what you can do with the wall post data.


ASP.NET Example
The code below (Download the full source code for this example) shows several things to have a powerful and flexible RSS/XML feed that is created from the JSON data you get from Facebook using Facebook's Graph API. It includes showing how to resolve 302 redirects to get the actual URL to profile pictures, using classes with JSON data, caching the data so you minimize the repeated process time of the data as well as other fields you could use. Check it out:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Text" %>

<script runat="server">
#Region "Miscellaneous Routines"
Public Function contentLimit(ByVal data As String) As String
' Limit the amount of text retained and filter out line breaks
data = System.Text.RegularExpressions.Regex.Replace(data, "[\r\n]", "")
if data.indexOf("<") > -1 OR data.indexOf(">") > -1 Then
Dim tmp_Filtered As String = String.Empty
Dim tmp_Flip As Integer = 0
For T As Integer = 0 TO Len(data)
Dim tmp_contentChar As String = Mid(data, T + 1, 1)
if tmp_contentChar = "<" Then : tmp_Flip = 1 : End if
if tmp_Flip = 0 Then : tmp_Filtered = tmp_Filtered & tmp_contentChar : End if
if tmp_contentChar = ">" Then : tmp_Flip = 0 : End if
Next
data = tmp_Filtered
End if
if Len(data) > rssDescriptionLen Then
data = Mid(data, 1, rssDescriptionLen) & "..."
End if
Return data
End Function
#End Region
#Region "Resolve 302 Redirects - Requires .NET4 Framework on Web Server"
Public Class respURLResolver
Public Function resolve302(ByVal URL As String, ByVal crawlAgent As String, ByVal crawlMethod As String) As String
Dim resolveData As String = URL
Try
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(resolveData), HttpWebRequest)
myRequest.UserAgent = crawlAgent
myRequest.Method = crawlMethod
' .NET4 Specific Component
Dim capturedUri As New Uri(resolveData)
Dim myResponse As WebResponse = CType(myRequest.GetResponse(), WebResponse)
If capturedUri.Equals(myResponse.ResponseUri) Then
' Pointing to self
Else
' Pointing somewhere else
resolveData = myResponse.ResponseUri.ToString()
End If
myResponse.Close()
Catch ex As Exception
resolveData = "[ERROR 1] " & ex.Message.ToString()
End Try
Return (resolveData)
End Function
End Class
#End Region
#Region "JSON Reader"
Public Class JSONReader
Public jsonData As New jsonResponse
Public Function jsonFetch(ByVal URL As String, ByVal crawlAgent As String, ByVal crawlMethod As String) As String
Dim buffSize As Integer = 2048
Dim crawlOutput As String = String.Empty
Dim crawlError As String = String.Empty
Try
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest)
myRequest.UserAgent = crawlAgent
myRequest.Method = crawlMethod
Dim myResponse As HttpWebResponse = CType(myRequest.GetResponse(), HttpWebResponse)
Dim streamResponse As Stream = myResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(buffSize) As [Char]
Dim lineStep As Integer = streamRead.Read(readBuff, 0, buffSize)
While lineStep > 0
Dim outputData As New [String](readBuff, 0, lineStep)
crawlOutput = crawlOutput & outputData
lineStep = streamRead.Read(readBuff, 0, buffSize)
End While
streamRead.Close()
streamResponse.Close()
myResponse.Close()
Catch ex As Exception
crawlError = "[ERROR 2] " & ex.Message.ToString()
End Try
if crawlError.length = 0 Then
crawlError = "success"
crawlOutput = crawlOutput.Replace(""""":", """unknown"":")
Try
Dim jsonDeserializer As New System.Web.Script.Serialization.JavaScriptSerializer
jsonData = jsonDeserializer.Deserialize(Of jsonResponse)(crawlOutput)
Catch exb As Exception
crawlError = "[ERROR 3] " & exb.Message.ToString()
End Try
End if
Return (crawlError)
End Function
End Class
#End Region
#Region "JSON Schema Definition Class For Facebook Wall"
Public Class jsonResponse
Private _data() As data
Public Property data() As data()
Get
Return _data
End Get
Set(ByVal value As data())
_data = value
End Set
End Property
End Class
Public Class data
' Define all of the simple data types
Private _id As String
Private _story As String
Private _message As String
Private _picture As String
Private _link As String
Private _source As String
Private _name As String
Private _description As String
Private _icon As String
Private _type As String
Private _object_id As String
Private _created_time As String
Private _updated_time As String
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property story() As String
Get
Return _story
End Get
Set(ByVal value As String)
_story = value
End Set
End Property
Public Property message() As String
Get
Return _message
End Get
Set(ByVal value As String)
_message = value
End Set
End Property
Public Property picture() As String
Get
Return _picture
End Get
Set(ByVal value As String)
_picture = value
End Set
End Property
Public Property link() As String
Get
Return _link
End Get
Set(ByVal value As String)
_link = value
End Set
End Property
Public Property source() As String
Get
Return _source
End Get
Set(ByVal value As String)
_source = value
End Set
End Property
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property
Public Property icon() As String
Get
Return _icon
End Get
Set(ByVal value As String)
_icon = value
End Set
End Property
Public Property type() As String
Get
Return _type
End Get
Set(ByVal value As String)
_type = value
End Set
End Property
Public Property object_id() As String
Get
Return _object_id
End Get
Set(ByVal value As String)
_object_id = value
End Set
End Property
Public Property created_time() As String
Get
Return _created_time
End Get
Set(ByVal value As String)
_created_time = value
End Set
End Property
Public Property updated_time() As String
Get
Return _updated_time
End Get
Set(ByVal value As String)
_updated_time = value
End Set
End Property

' Instantiate the non-arrayed child classes defined inside the parent class "data"
Public Sub New()
_from = New dataFrom
_application = New dataApplication
_likes = New dataLikes
_comments = New dataComments
End Sub

' Define the non-arrayed child classes that must be instantiated inside the parent class "data" but have arrayed child classes within them
Private _likes As dataLikes
Public Property likes As dataLikes
Get
Return _likes
End Get
Set(ByVal value As dataLikes)
_likes = value
End Set
End Property
Public Class dataLikes
Private _count As String
Private _data() As likesData
Public Property count() As String
Get
Return _count
End Get
Set(ByVal value As String)
_count = value
End Set
End Property
Public Property data() As likesData()
Get
Return _data
End Get
Set(ByVal value As likesData())
_data = value
End Set
End Property
Public Class likesData
Private _name As String
Private _id As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
End Class
End Class
Private _comments As dataComments
Public Property comments As dataComments
Get
Return _comments
End Get
Set(ByVal value As dataComments)
_comments = value
End Set
End Property
Public Class dataComments
Private _count As String
Private _data() As commentsData
Public Property count() As String
Get
Return _count
End Get
Set(ByVal value As String)
_count = value
End Set
End Property
Public Property data() As commentsData()
Get
Return _data
End Get
Set(ByVal value As commentsData())
_data = value
End Set
End Property
Public Class commentsData
Private _id As String
Private _message As String
Private _created_time As String
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
Public Property message() As String
Get
Return _message
End Get
Set(ByVal value As String)
_message = value
End Set
End Property
Public Property created_time() As String
Get
Return _created_time
End Get
Set(ByVal value As String)
_created_time = value
End Set
End Property
Public Sub New()
_from = New commentsDataFrom
End Sub
Private _from As commentsDataFrom
Public Property from As commentsDataFrom
Get
Return _from
End Get
Set(ByVal value As commentsDataFrom)
_from = value
End Set
End Property
Public Class commentsDataFrom
Private _name As String
Private _id As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
End Class

End Class
End Class
Private _from As dataFrom
Public Property from As dataFrom
Get
Return _from
End Get
Set(ByVal value As dataFrom)
_from = value
End Set
End Property
Public Class dataFrom
Private _name As String
Private _category As String
Private _id As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property category() As String
Get
Return _category
End Get
Set(ByVal value As String)
_category = value
End Set
End Property
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
End Class
Private _application As dataApplication
Public Property application As dataApplication
Get
Return _application
End Get
Set(ByVal value As dataApplication)
_application = value
End Set
End Property
Public Class dataApplication
Private _name As String
' Not valid as an identifier since "namespace" is a keyword
' Private _namespace As String
Private _id As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
' Not valid as an identifier since "namespace" is a keyword
'Public Property namespace() As String
' Get
' Return _namespace
' End Get
' Set(ByVal value As String)
' _namespace = value
' End Set
'End Property
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
End Class

' Define the arrayed child classes defined inside of the parent class "data"
Private _actions() As dataActions
Public Property actions() As dataActions()
Get
Return _actions
End Get
Set(ByVal value As dataActions())
_actions = value
End Set
End Property
Public Class dataActions
Private _name As String
Private _link As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property link() As String
Get
Return _link
End Get
Set(ByVal value As String)
_link = value
End Set
End Property
End Class
Private _properties() As dataProperties
Public Property properties() As dataProperties()
Get
Return _properties
End Get
Set(ByVal value As dataProperties())
_properties = value
End Set
End Property
Public Class dataProperties
Private _name As String
Private _text As String
Private _href As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property text() As String
Get
Return _text
End Get
Set(ByVal value As String)
_text = value
End Set
End Property
Public Property href() As String
Get
Return _href
End Get
Set(ByVal value As String)
_href = value
End Set
End Property
End Class
End Class
#End Region
#Region "Using the JSON Reader Class with Facebook Graph API to get Public Group Wall Posts"
Private facebookAccessToken As String = "11111111111111111-111-11111sa11mm11nn11GBZW" ' Define the Facebook Access Token
' NOTE: In order to get an access token, you must first...
' 1. Login into Facebook with an account
' 2. Create a new "app" at https://developers.facebook.com/apps/
' 3. You will need to provide a unique application name and namespace which can be virtually whatever you want
' 4. Provide a mobile number or credit card; if mobile number you will receive a text with the confirmation code
' 5. You will be issued (1) application ID, (2) application secret
' 6. Proceed to get the access token (https://developers.facebook.com/docs/authentication/applications/)
' 7. Alternatively enter the following URL substituting "YOUR_APP_ID" and "YOUR_APP_SECRET" with your application ID and application secret
' https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials
' 8. The response should contain the tag "access_token" with the value being the access token

Private facebookPublicGroupWallID As String = "NameOfPublicGrp" ' Define the Facebook Public Group Wall
' NOTE: Can alternatively be the ID of the group wall
' If you know the friendly name of a public group wall, you can use that name instead of the group ID of the group wall. However, if you want to get the group ID, here's how you do it...
' 1. Method #1: Go to the Graph API Explorer at https://developers.facebook.com/tools/explorer
' 2. Method #1: Under the tab "Graph API" enter the name of the public group wall in the URL bar and submit
' 3. Method #2: Enter the following URL substituting "PUBLIC_WALL_NAME" with the name of the public group wall
' https://developers.facebook.com/tools/explorer?method=GET&path=PUBLIC_WALL_NAME
Private rssCacheClear As Integer = 0 ' Maintentance - 1 = clear server-cache, 0 = do not clear server-cache
Private rssCacheUse As Integer = 1 ' 0 = do not save the posts to the server cache to recall from to build future requests, 1 = use the server cache
Private numberOfPostsShow As Integer = 6 ' Maximum number of wall posts and comments to retrieve
Private rssDescriptionLen As Integer = 60 ' Number of characters to allow in the poster's post (description)
Private rssIncludeImg As Integer = 1 ' 0 = do not include the thumbnail image of posters in description, 1 = include
Private rssIncludeHeader As Integer = 0 ' 0 = do not include RSS provider data (below), 1 = include
Private rssShowErrors As Integer = 0 ' 0 = do not show server-side errors with wall data retrieval, 1 = show
Private feedName As String = "ServerCacheName" ' Name of the feed to be created; serves as the name of the cache object name of the feed
Private feed_title As String = "Feed Title"
Private feed_link As String = "http://www.yoursite.com/"
Private feed_description As String = "Feed Description"
Private feed_language As String = "en-us"
Private feed_pubdate As String = "20 Apr 2007 9:40:00 GMT"
Private feed_copyright As String = String.Empty
Private feed_webmaster As String = "webmaster@yoursite.com"

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim thisDay As DateTime = DateTime.Today
Dim pullState As Integer = rssCacheClear
Dim elemLines(,) As String
Dim elemLinesCount As Integer = 0
Dim feedContent As String = String.Empty
' Use cache if present
If HttpContext.Current.Cache(feedName) Is Nothing Then
' Server cache not present; build the feed
pullState = 0
Else
' Use the server cache
feedContent = CType(HttpContext.Current.Cache(feedName), String)
End if

if rssCacheClear = 1 Then
pullState = 1
feedContent = ""
End if

if pullState = 0 Then
' Construct the URL to query Facebook for the JSON response containing posts made to the group wall
Dim jsonURL As String = "https://graph.facebook.com/" & facebookPublicGroupWallID & "/posts?access_token=" & facebookAccessToken
' Make query to get JSON
Dim resolveRedirects As New respURLResolver
Dim jsonInteract As New JSONReader
Dim jsonQueryData As String = jsonInteract.jsonFetch(jsonURL, Request.UserAgent, "GET")
if jsonQueryData = "success" Then
' Query successful; process JSON
' Extract Content
For jsonDataBlock As Integer = 0 TO jsonInteract.jsonData.data.length
if elemLinesCount < numberOfPostsShow Then
Dim storyAuthorID As String = String.Empty
Dim storyAuthor As String = String.Empty
Dim storyStatement As String = String.Empty
Dim storyTime As String = String.Empty
Dim storyPhoto As String = String.Empty
' Get Group Wall Main Post
storyAuthorID = jsonInteract.jsonData.data(jsonDataBlock).from.id
storyAuthor = jsonInteract.jsonData.data(jsonDataBlock).from.name
' Generally only one or the other will exist in the data block
if Not jsonInteract.jsonData.data(jsonDataBlock).message Is Nothing Then
storyStatement = jsonInteract.jsonData.data(jsonDataBlock).message
Elseif Not jsonInteract.jsonData.data(jsonDataBlock).story Is Nothing Then
storyStatement = jsonInteract.jsonData.data(jsonDataBlock).story
Elseif Not jsonInteract.jsonData.data(jsonDataBlock).description Is Nothing Then
storyStatement = jsonInteract.jsonData.data(jsonDataBlock).description
End if
storyTime = jsonInteract.jsonData.data(jsonDataBlock).created_time
storyPhoto = resolveRedirects.resolve302("https://graph.facebook.com/" & storyAuthorID & "/picture", Request.UserAgent, "GET")
if storyPhoto.indexOf("[ERROR") > -1 Then
if rssShowErrors = 1 Then
storyStatement = storyPhoto
storyTime = thisDay.ToString()
End if
storyPhoto = "https://graph.facebook.com/" & storyAuthorID & "/picture"
End if
' Filter Content
storyAuthor = HttpUtility.HtmlDecode(storyAuthor)
storyStatement = contentLimit(HttpUtility.HtmlDecode(storyStatement))
' Save Content
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = storyPhoto
elemLines(1, elemLinesCount) = storyAuthor
elemLines(2, elemLinesCount) = storyStatement
elemLines(3, elemLinesCount) = storyTime
elemLinesCount = elemLinesCount + 1
Try
' Get Comments Associated To Main Post
if CType(jsonInteract.jsonData.data(jsonDataBlock).comments.count, Integer) > 0 Then
Dim commentAuthorID As String = String.Empty
Dim commentAuthor As String = String.Empty
Dim commentStatement As String = String.Empty
Dim commentTime As String = String.Empty
Dim commentPhoto As String = String.Empty
For commentCount As Integer = 0 TO CType(jsonInteract.jsonData.data(jsonDataBlock).comments.count, Integer) - 1
if elemLinesCount < numberOfPostsShow Then
commentAuthorID = jsonInteract.jsonData.data(jsonDataBlock).comments.data(commentCount).from.id
commentAuthor = jsonInteract.jsonData.data(jsonDataBlock).comments.data(commentCount).from.name
commentStatement = jsonInteract.jsonData.data(jsonDataBlock).comments.data(commentCount).message
commentTime = jsonInteract.jsonData.data(jsonDataBlock).comments.data(commentCount).created_time
commentPhoto = resolveRedirects.resolve302("https://graph.facebook.com/" & commentAuthorID & "/picture", Request.UserAgent, "GET")
if commentPhoto.indexOf("[ERROR") > -1 Then
if rssShowErrors = 1 Then
commentStatement = commentPhoto
commentTime = thisDay.ToString()
End if
commentPhoto = "https://graph.facebook.com/" & storyAuthorID & "/picture"
End if
' Filter Content
commentAuthor = HttpUtility.HtmlDecode(commentAuthor)
commentStatement = contentLimit(HttpUtility.HtmlDecode(commentStatement))
' Save Content
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = commentPhoto
elemLines(1, elemLinesCount) = commentAuthor
elemLines(2, elemLinesCount) = commentStatement
elemLines(3, elemLinesCount) = commentTime
elemLinesCount = elemLinesCount + 1
End if
Next
End if
Catch exComment As Exception
' An error was generated
if rssShowErrors = 1 Then
' Save Content
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = ""
elemLines(1, elemLinesCount) = "Comment Retrieve Error"
elemLines(2, elemLinesCount) = HttpUtility.HtmlDecode(exComment.ToString())
elemLines(3, elemLinesCount) = thisDay.ToString()
elemLinesCount = elemLinesCount + 1
End if
End Try
End if
' ADDITIONAL JSON DATA YOU CAN RETRIEVE
' "application" jsonInteract.jsonData.data(jsonDataBlock).application.name
' "actions" jsonInteract.jsonData.data(jsonDataBlock).actions(0).name - an array so you'll need to see if it contains anything; look at class for more
' "picture" jsonInteract.jsonData.data(jsonDataBlock).picture
' "link" jsonInteract.jsonData.data(jsonDataBlock).link
' "source" jsonInteract.jsonData.data(jsonDataBlock).source
' "name" jsonInteract.jsonData.data(jsonDataBlock).name
' "properties" jsonInteract.jsonData.data(jsonDataBlock).properties(0).name - an array so you'll need to see if it contains anything; look at class for more
' "description" jsonInteract.jsonData.data(jsonDataBlock).description
' "icon" jsonInteract.jsonData.data(jsonDataBlock).icon
' "type" jsonInteract.jsonData.data(jsonDataBlock).type
' "object_id" jsonInteract.jsonData.data(jsonDataBlock).object_id
' "updated_time" jsonInteract.jsonData.data(jsonDataBlock).updated_time
' "likes (count)" jsonInteract.jsonData.data(jsonDataBlock).likes.count
' "likes (data)" jsonInteract.jsonData.data(jsonDataBlock).likes.data(0).name - an array so you'll need to see if it contains anything; look at class for more
Next
Else
' An error was generated
if rssShowErrors = 1 Then
' Save Content
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = ""
elemLines(1, elemLinesCount) = "JSON Retrieve Error"
elemLines(2, elemLinesCount) = jsonQueryData
elemLines(3, elemLinesCount) = thisDay.ToString()
elemLinesCount = elemLinesCount + 1
Else
' Save Content
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = ""
elemLines(1, elemLinesCount) = "System"
elemLines(2, elemLinesCount) = "The feed is not available. Please try back later."
elemLines(3, elemLinesCount) = thisDay.ToString()
elemLinesCount = elemLinesCount + 1
End if
End if
Else
' Clear Cache
If Not HttpContext.Current.Cache(feedName) Is Nothing Then
HttpContext.Current.Cache.Remove(feedName)
End if
' Save Content
' Indicate the cache has been cleared
ReDim Preserve elemLines(3, elemLinesCount)
elemLines(0, elemLinesCount) = ""
elemLines(1, elemLinesCount) = "System"
elemLines(2, elemLinesCount) = "The cache has been cleared."
elemLines(3, elemLinesCount) = thisDay.ToString()
elemLinesCount = elemLinesCount + 1
End if

' Generate Output
if elemLinesCount > 0 Then
if Len(feedContent) = 0 Then
Dim feedStep As Integer = 0
For R As Integer = 0 To elemLinesCount - 1
feedContent = feedContent & "<item>" & vbCrLf
feedContent = feedContent & "<title>" & HttpUtility.HtmlEncode(feed_title) & "</title>" & vbCrLf
feedContent = feedContent & "<link>" & HttpUtility.HtmlEncode(feed_link) & "</link>" & vbCrLf
if rssIncludeImg = 1 Then
feedContent = feedContent & "<description>" & HttpUtility.HtmlEncode("<img align=""left"" src=""" & elemLines(0, R) & """ border=""0"" /> ") & HttpUtility.HtmlEncode(Replace(elemLines(2, R), "'", "'")) & "</description>" & vbCrLf
Else
feedContent = feedContent & "<description>" & HttpUtility.HtmlEncode(Replace(elemLines(2, R), "'", "'")) & "</description>" & vbCrLf
End if
feedContent = feedContent & "<author>" & HttpUtility.HtmlEncode(elemLines(1, R)) & "</author>" & vbCrLf
feedContent = feedContent & "<date>" & elemLines(3, R) & "</date>" & vbCrLf
feedContent = feedContent & "</item>" & vbCrLf
Next
End if
Else
feedContent = feedContent & "<item>" & vbCrLf
feedContent = feedContent & "<title>Unknown Error</title>" & vbCrLf
feedContent = feedContent & "<link></link>" & vbCrLf
feedContent = feedContent & "<description>An unknown error has occurred.</description>" & vbCrLf
feedContent = feedContent & "<author>Server</author>" & vbCrLf
feedContent = feedContent & "<date>" & feed_pubdate & "</date>" & vbCrLf
feedContent = feedContent & "</item>" & vbCrLf
End if

' Add RSS Envelope, if specified
Dim rssFeed As String = String.Empty
if rssIncludeHeader = 1 Then
rssFeed = rssFeed & "<rss version=""2.0"">" & vbCrLf
End if
if feedContent.indexOf("<channel>") = -1 Then
rssFeed = rssFeed & "<channel>" & vbCrLf
End if
If rssIncludeHeader = 1 Then
rssFeed = rssFeed & "<title>" & HttpUtility.HtmlEncode(feed_title) & "</title>" & vbCrLf
rssFeed = rssFeed & "<link>" & HttpUtility.HtmlEncode(feed_link) & "</link>" & vbCrLf
rssFeed = rssFeed & "<description>" & feed_description & "</description>" & vbCrLf
rssFeed = rssFeed & "<language>" & feed_language & "</language>" & vbCrLf
rssFeed = rssFeed & "<date>" & feed_pubdate & "</date>" & vbCrLf
rssFeed = rssFeed & "<copyright>" & HttpUtility.HtmlEncode(feed_copyright) & "</copyright>" & vbCrLf
rssFeed = rssFeed & "<webmaster>" & feed_webmaster & "</webmaster>" & vbCrLf
End If
rssFeed = rssFeed & feedContent
if feedContent.indexOf("</channel>") = -1 Then
rssFeed = rssFeed & "</channel>" & vbCrLf
End if
if rssIncludeHeader = 1 Then
rssFeed = rssFeed & "</rss>"
End if

' Add RSS to Server Cache
if pullState = 0 And rssCacheUse = 1 And rssCacheClear = 0 Then
HttpContext.Current.Cache.Add(feedName, rssFeed, Nothing, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Normal, Nothing)
End if

' Generate Feed
Response.Buffer = False
If rssIncludeHeader = 1 Then
Response.ContentType = "application/rss+xml"
Else
Response.ContentType = "text/xml"
End If
Response.Write("<" & "?" & "xml version=""1.0"" encoding=""utf-8""" & "?" & ">" & vbCrLf)
Response.Write(rssFeed)
End Sub
#End Region
</script>


About Joe