Click here to Skip to main content
15,070,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am trying to create a media Rss feed so that I can use a cooliris plugin to view the images in my SQL database. I have created a standard rss feed and it works, however, I am having trouble creating the media:content tags that the cooliris plugin needs to find the images. This is what I have in my code behind so far. How do I add the media:content tags to WriteElementStrings so that they will show the plugin my image location? Sorry if I am being unclear of what I am asking, but feel free to ask any questions.

Thanks in advance...

As for the code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
using System.Data.SqlClient;
public partial class Pages_MyFeed : System.Web.UI.Page
{
        string strConnection = "Data Source=Source;User ID=ID;Password=PWD;";
        protected void Page_Load(object sender, EventArgs e)
        {
        if (!IsPostBack)
        {
            // Clear the response buffer contents
            Response.Clear();
            Response.ContentType = "text/xml";
            XmlTextWriter rssFeed = new XmlTextWriter
            (Response.OutputStream, Encoding.UTF8);
            //writing RSS tags 
            rssFeed.WriteStartDocument();
            rssFeed.WriteStartElement("rss");
            rssFeed.WriteAttributeString("version", "2.0");
            rssFeed.WriteAttributeString("xmlns:media", "http://search.yahoo.com/mrss/");
            rssFeed.WriteAttributeString("xmlns:atom", "http://www.w3.org/2005/Atom");
            rssFeed.WriteStartElement("channel");
            rssFeed.WriteElementString("title", "Hat Details");
            rssFeed.WriteElementString("description", "Custom Hat Details");
            rssFeed.WriteElementString("link", "http://www.myheadpiece.com");
            rssFeed.WriteElementString("image", "URL");

            // create sql connection and connect to database
            SqlConnection con = new SqlConnection(strConnection);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Find_all";
            cmd.Connection = con;
            con.Open();
            SqlDataReader dReader;
            dReader = cmd.ExecuteReader();
            while (dReader.Read())
            {
                string url = "http://www.myheadpiece.com/Images/Hats/" + dReader["URL"] + ".png";
                rssFeed.WriteStartElement("item");
                rssFeed.WriteElementString("title", dReader["HatName"].ToString());
                rssFeed.WriteElementString("description", dReader["HatName"].ToString());
                rssFeed.WriteElementString("link", url);
                rssFeed.WriteElementString("image", url);
                rssFeed.WriteElementString("pubDate", DateTime.Now.ToString());
                rssFeed.WriteEndElement();
            }
            dReader.Close();
            con.Close();
            rssFeed.WriteEndElement();
            rssFeed.WriteEndElement();
            rssFeed.WriteEndDocument();
            rssFeed.Flush();
            rssFeed.Close();
            Response.End();
        }
    }
}
Posted
Updated 31-Jul-11 9:36am
v2
Comments
Herman<T>.Instance 31-Jul-11 15:58pm
   
what is in the line
string url = "http://www.myheadpiece.com/Images/Hats/" + dReader["URL"] + ".png"
the value of dReader["URL"]? does this database field also holds the image name?
what is the value of string url after it is filled? Did you debug the code? Set a breakpoint on the line
rssFeed.WriteStartElement("item");
and check the value of url.
I3I2UNO 31-Jul-11 16:04pm
   
that string is just the location of the images that I want to load into my rss feed. So yes this field holds the image name. It loads all of this correctly into my rss. You can take a look here.

http://myheadpiece.com/pages/myfeed.aspx
Herman<T>.Instance 31-Jul-11 16:19pm
   
if i do click your url i get an image. What kind of behaviour did you expect?
I3I2UNO 31-Jul-11 16:21pm
   
I'm trying to create a Media Rss file so that my cooliris plugin can understand where my image is located. The rssFeed.WriteElementString("image", url); does not do this. I need to basically make the rss feed say (media:content url="http://www.myheadpiece.com/Images/Hats/") (parentheses are supposed to be <>) but I don't know how to emulate this in my code behind.
Herman<T>.Instance 1-Aug-11 3:42am
   
look here : http://www.techtalkz.com/c-c-sharp/126396-xmltextwriter-xmldocument.html

1 solution

So obviously my question is not making much sense so I will try to clarify.

So if you take a look at my current feed here: http://myheadpiece.com/pages/myfeed.aspx[^]

You can see the media:content tag. But if you take a look at this feed from flickr: http://www.flickr.com/services/feeds/photos_public.gne?tags=toy&format=rss_200[^]

This feed is in the correct format that my plugin can read. As you can see the media:content tag has additional information within the tag that is different from my feed. Obviously I can accomplish this by writing all of the xml in a static manner, but I want to do this dynamically from my SQL database that I have already created. So my question is this, how can I write my code in my code behind to emulate the media:content tags that are seen in the flickr feed so that my plugin can read my own mRSS feed?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900