?
Solved

How to add item image information to rss news feed using ASP.NET

Posted on 2014-09-04
1
Medium Priority
?
553 Views
Last Modified: 2014-09-05
I'm trying to include an image in the rss feed xml I'm generateing using XmlTextWriter. I have two problems:

1. What is the correct output format for this information? I found one source that suggests it should be formatted as follows:

<item>...<media:content medium="image" url="http://www.somedomain.com/images/someimage.jpg"></media:content></item>

But other sources seem to suggest I should be using the enclosure element.

2. I tried to use the following code to generate my xml but when I look at it via the browser, I get "Reference to undeclared namespace prefix: 'media'."

Here's the code:
        Response.Clear()
        Response.ContentType = "text/xml"
        Dim xtwFeed As XmlTextWriter = New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        xtwFeed.WriteStartDocument()
        'The mandatory rss tag

        xtwFeed.WriteStartElement("rss")
        xtwFeed.WriteAttributeString("version", "2.0")

        'The channel tag contains RSS feed details
        xtwFeed.WriteStartElement("channel")
        xtwFeed.WriteElementString("title", "My News :: News")
        xtwFeed.WriteElementString("link", "http://www.mydomain.net/news.aspx")
        xtwFeed.WriteElementString("description", "The latest news from My domain.")
        xtwFeed.WriteElementString("copyright", "Copyright 2010 My Group. All rights reserved.")
        xtwFeed.WriteElementString("category", "News")
        xtwFeed.WriteElementString("ttl", "120")

        xtwFeed.WriteStartElement("image")
        xtwFeed.WriteElementString("url", "http://www.mydomain.net/images/logo.jpg")
        xtwFeed.WriteElementString("title", "The latest news from My Group.")
        xtwFeed.WriteElementString("link", "http://www.mydomain.net/")
        xtwFeed.WriteEndElement()

        Dim buildDate As Date = TimeZoneInfo.ConvertTimeToUtc(Now())
        xtwFeed.WriteElementString("lastBuildDate", buildDate.ToString("R"))
        For Each dr As DataRow In T.Rows
            xtwFeed.WriteStartElement("item")
            xtwFeed.WriteElementString("title", FormatForXML(dr.Item("nevTitle").ToString()))
            xtwFeed.WriteElementString("description", FormatForXML(dr.Item("nevDesc").ToString()))
            xtwFeed.WriteElementString("link", "http://www.mydomain.net/newsdetail.aspx?ID=" & dr.Item("nevID"))
            Dim d As Date = TimeZoneInfo.ConvertTimeToUtc(dr.Item("nevStartDate"))
            xtwFeed.WriteElementString("pubDate", d.ToString("R"))

            If Not DBNull.Value.Equals(dr.Item("nevPic1")) Then
               xtwFeed.WriteStartElement("media:content")
                xtwFeed.WriteAttributeString("medium", "image")
                xtwFeed.WriteAttributeString("url", dr.Item("nevPic1"))
                xtwFeed.WriteEndElement()
            End If

            xtwFeed.WriteEndElement()
        Next

        'Close all tags 
        xtwFeed.WriteEndElement()
        xtwFeed.WriteEndElement()
        xtwFeed.WriteEndDocument()
        xtwFeed.Flush()
        xtwFeed.Close()
        Response.End()

Open in new window


This code writes the media:content as <media:content medium="image" url="/images/NewsEvents/Image01.jpg" />.

My goal is to use this feed as the input to DevExpress's ASPxNewsControl.

Thank you for any assistance you can provide.
0
Comment
Question by:ZekeLA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
ZekeLA earned 0 total points
ID: 40305887
I found the problem. I needed to add the following code after the line with the 2.0 version attribute:

xtwFeed.WriteAttributeString("xmlns:media", "http://search.yahoo.com/mrss/")    ' note that media must be spelled as lowercase

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question