Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas T 66 posts 227 karma points
    Apr 07, 2015 @ 07:17
    Thomas T
    0

    RichTextEditor data type throws error when writing RSS feed

    I added posts from blog to RSS feed. Everything works fine. But I can't show summary of each post. I get the values of each post through below code,

    IPublishedContent blog = Model.Content.AncestorOrSelf("SmBlog");

    IEnumerable<IPublishedContent> posts = blog.Descendants("SmBlogPost").OrderBy("smBlogDate desc");

    Then I write RSS feed as below,

    Response.ContentType = "text/xml";

    XmlTextWriter feedWriter = new XmlTextWriter(Response.OutputStream, System.Text.Encoding.UTF8);

    feedWriter.WriteStartDocument(); feedWriter.WriteStartElement("rss");

    feedWriter.WriteAttributeString("version", "2.0");


    feedWriter.WriteStartElement("channel");

    feedWriter.WriteElementString("title", Model.Content.GetProperty("smBlogRssTitle").Value.ToString());

    feedWriter.WriteElementString("description", Model.Content.GetProperty("smBlogRssDescription").Value.ToString());

    feedWriter.WriteElementString("copyright", Model.Content.GetProperty("smBlogRssCopyright").Value.ToString());

    feedWriter.WriteElementString("pubDate", postDate.ToString("ddd, dd MMMM yyyy HH:mm:ss"));

    foreach (dynamic post in posts)

        {

            feedWriter.WriteStartElement("item");

            feedWriter.WriteElementString("title", post.GetPropertyValue("smBlogTitle"));

    feedWriter.WriteElementString("description",post.GetPropertyValue("smBlogSummary") );

            feedWriter.WriteElementString("guid", Umbraco.NiceUrlWithDomain(post.Id));

            feedWriter.WriteElementString("pubDate",

    Convert.ToDateTime(post.GetPropertyValue("smBlogDate")).ToString("ddd, dd MMMM yyyy HH:mm:ss"));

            feedWriter.WriteEndElement();

        }

       feedWriter.WriteEndElement();    feedWriter.WriteEndElement();

        feedWriter.WriteEndDocument();    feedWriter.Flush();

        feedWriter.Close();    Response.End();

     

    post.GetPropertyValue("smBlogSummary") );  throws error as below,

    When I change its data type to 'TextSring' from 'RichTextEditor', it works fine. But I need to display summary with 'RichTextEditor' data type.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 07, 2015 @ 09:01
    Jan Skovgaard
    0

    Hi Thomas

    It's probablu because your RIch Text editor contains HTML, which makes the RSS generator throw up. So you should probably use something like this http://www.dotnetperls.com/remove-html-tags - Can't remember of there is a stripHtml function available though.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft