Een user control wat een RSS feed genereert op basis van het Node id in Umbraco

Voorbeeld Code:

 

using umbraco.presentation.nodeFactory;

public partial class usercontrols_Teus_RSS : System.Web.UI.UserControl
{
    private int resoucenodeid;
    public int resourcesNodeId {
        get { return this.resoucenodeid; }
        set { this.resoucenodeid = value; } 
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "text/xml";

        writeRSS();
    }

    private void writeRSS()
    {
        XmlTextWriter xtw = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

        xtw.WriteStartDocument();
        string processtext = "type=\"text/xsl\" href=\"rss.xsl\"";
        xtw.WriteProcessingInstruction("xml-stylesheet", processtext);
        xtw.WriteStartElement("rss");
        xtw.WriteAttributeString("version", "2.0");
        xtw.WriteStartElement("channel");
        xtw.WriteElementString("title", "Lijst met laatste aantekeningen");
        xtw.WriteElementString("link", "");
        xtw.WriteElementString("description", "Csharp Code");

        writeRSSelementens(xtw);

        xtw.WriteEndElement();
        xtw.WriteEndElement();
        xtw.WriteEndDocument();

        xtw.Flush();
        xtw.Close();
    }

    private void writeRSSelementens(XmlTextWriter xtw)
    {
        if (this.resoucenodeid > 0)
        {
            var node = new Node(this.resourcesNodeId);
            if (node.Children.Count > 0)
            {
                foreach (Node item in node.Children )
                {
                    writeRSSelementen(xtw, item);
                }
            }
        }
    }

    private void writeRSSelementen(XmlTextWriter xtw, Node n)
    {
        foreach (Node item in n.Children)
        {
            //if (item.ContentType.Alias == "Aantekening")
            //{
            xtw.WriteStartElement("item");
            xtw.WriteElementString("title", item.Name);
            xtw.WriteElementString("description", item.GetProperty("Inleiding").Value.ToString());
            xtw.WriteElementString("link", "" + umbraco.library.NiceUrl (item.Id));
            xtw.WriteElementString("pubDate",
             XmlConvert.ToString(Convert.ToDateTime(item.UpdateDate)));
            xtw.WriteEndElement();
            // }
            if (n.Children.Count > 0)
            {
                    writeRSSelementen(xtw, item );
            }
        }

    }
}

Had mischien nog iets handiger gekunt, maar werkt het werkt goed !!

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!