Subscribe: Create ASP.NET Syndication Feeds with SqlConnection and VB.NET - Stack Overflow
http://stackoverflow.com/feeds/question/880954
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
create net  create  dim  end  feed  feedformats  feeds sqlconnection  net syndication  net  new  posts  sqlconnection net  syndication  system 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Create ASP.NET Syndication Feeds with SqlConnection and VB.NET - Stack Overflow

Create ASP.NET Syndication Feeds with SqlConnection and VB.NET - Stack Overflow



most recent 30 from stackoverflow.com



Updated: 2018-04-19T13:00:51Z

 



Create ASP.NET Syndication Feeds with SqlConnection and VB.NET

2010-11-11T03:54:09Z

This seems to be a great article by Scott Mitchell for creating syndicated feeds in ASP.NET 3.5. The problem for me is that it uses C# and Linq, which I'm not as sharp on at the current time.

http://dotnetslackers.com/articles/aspnet/How-to-create-a-syndication-feed-for-your-website.aspx

Does anyone know where an example might exist for the System.ServiceModel.Syndication namespace that can produce a syndicated feed like this article using VB.NET and a SQLConnection object?

I've looked around and every example seems to be produced in C# and Linq (which is probably a testament to my need to learn them soon rather than later).




Answer by Gary.Ray for Create ASP.NET Syndication Feeds with SqlConnection and VB.NET

2009-05-19T04:29:23Z

I don't know of an example using those objects in VB.Net, but there are several ways to transform c# code to VB.Net. You could use an IDE like SharpDevelop, you could use any of several free online converters.

My favorite technique would be to download or cut and paste the source into visual studio and compile the project in C#. Then use Reflector to disassemble the IL to VB.Net. By doing that you can compare the C# to VB.Net and it may help you see the similarities and pick up C# faster if that is what you would like to do.




Answer by Jakob Gade for Create ASP.NET Syndication Feeds with SqlConnection and VB.NET

2010-11-11T03:54:09Z

You’ve probably figured it out by now, but here’s an implementation for completeness and some VB love (and an attempt for the Necromancer badge. :)

The aspx page is simple, note the 60 second cache:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="YourProject._Default" %>
<%@ OutputCache Duration="60" VaryByParam="Type" %>

You probably want to consider using an HttpHandler instead, but this will work just fine too.

The code behind:

Imports System.ServiceModel.Syndication
Imports System.Xml

Partial Public Class _Default
  Inherits System.Web.UI.Page

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim dbConn As String = "[your db connection]"
    Dim format As FeedFormats = GetFeedFormat()
    Dim posts As New List(Of SyndicationItem)

    Using cnn As New SqlClient.SqlConnection(dbConn)
      cnn.Open()

      Using cmd As New SqlClient.SqlCommand("SELECT ID, Title, Text, Url, Created FROM Posts", cnn)
        Dim reader As SqlClient.SqlDataReader = cmd.ExecuteReader

        While reader.Read
          Dim item As New SyndicationItem(reader.Item("Title"), reader("Text"), New Uri(reader("Url")))

          posts.Add(item)
        End While
      End Using
    End Using

    Dim feed As New SyndicationFeed("Your feed title", "Your feed description", New Uri("http://yourdomain.com"), posts)

    Using feedWriter As XmlWriter = XmlWriter.Create(Response.OutputStream)
      Select Case format
        Case FeedFormats.Atom
          Response.ContentType = "application/rss+xml"

          Dim atomFormatter As New Atom10FeedFormatter(feed)
          atomFormatter.WriteTo(feedWriter)
        Case FeedFormats.Rss
          Response.ContentType = "application/atom+xml"

          Dim rssFormatter As New Rss20FeedFormatter(feed)
          rssFormatter.WriteTo(feedWriter)
      End Select
    End Using
  End Sub

  Private Function GetFeedFormat() As FeedFormats
    If Request.QueryString("format") = "atom" Then
      Return FeedFormats.Atom
    Else
      Return FeedFormats.Rss
    End If
  End Function

  Public Enum FeedFormats
    Rss = 1
    Atom = 2
  End Enum
End Class

Finally, for super-completeness, the SQL script for creating the table:

CREATE TABLE [dbo].[Posts](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [Title] [nvarchar](50) NOT NULL,
 [Text] [ntext] NOT NULL,
 [Url] [nvarchar](50) NOT NULL,
 [Created] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_Posts] PRIMARY KEY CLUSTERED 
(
 [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[Posts] ADD  CONSTRAINT [DF_Posts_Url]  DEFAULT ('') FOR [Url]
GO

ALTER TABLE [dbo].[Posts] ADD  CONSTRAINT [DF_Posts_Created]  DEFAULT (getdate()) FOR [Created]
GO

Done. VB.NET, a SQL Connection, the System.ServiceModel.Syndication namespace, and no LINQ. :)

Update: Got the Necromancer badge on 11-11-2010. Yay! Thanks! :)