Limiting Item description size of RSS feed in BE

Aug 22, 2010 at 5:44 AM

Is it possible to reduce the no of Chars that is displayed in Blog Engine Feeds ? by Default the whole post is published in feeds.

Kindly help..

Coordinator
Aug 23, 2010 at 10:15 AM

You can use an Extension to control the #/ characters when the post is being output in the feed.

If you look at the existing BreakPost.cs extension in the App_Code\Extensions folder ... in Post_Serving, it checks the "Location".  The last IF statement is checking to see if the Location is ServingLocation.Feed.  If so, it removes the [more] tag.  This part you probably don't need.  But where you see this code:

else if (e.Location == ServingLocation.Feed)
{
	e.Body = e.Body.Replace("[more]", string.Empty);
}
... you could change that to something like:

else if (e.Location == ServingLocation.Feed)
{
	if (e.Body.Length > 300)
		e.Body = e.Body.Substring(0, 300) + "...";
}

Aug 24, 2010 at 1:14 PM

Using the substring will cause the text to be chopped mid word, so "this is my great blog post" would end up looking like 

e.g. this is my gr.....

this method will make sure you get the text whole words nearist your selected lenght

 

        public static string Teaser(string input, int size)
        {
            if (!string.IsNullOrEmpty(input))
            {
                if (size < input.Length)
                {
                    int endlength = input.IndexOf(" ", size);

                    if (endlength != -1)
                    {
                        input = input.Substring(0, endlength);
                    }
                }
            }

            return input;
        }

Try.

 

else if (e.Location == ServingLocation.Feed)
{
if (e.Body.Length > 300)
e.Body = Teaser(e.Body, 300) + "...";
}