WorldofASP.NET : ASP.NET Directory, Tutorial, Hosting, and Source Code
You are 1 of 232 users


RSS Blog Roller Code Update

Blogger : Dan Wahlins WebLog
All posts : All posts by Dan Wahlins WebLog
Category : ASP.NET
Blogged date : 2006 Oct 22

I've updated the original blog roller code posted awhile back since a few minor changes were made.  On the homepage of Interface Technical Training we only show the first 250 characters of employee blogs.  However, people were using tools that injected so much HTML/CSS into their blog that no real text from the blog could be found in the first 250 characters (just HTML tags).  To remedy this problem, all HTML is now stripped out of the summary text and a small routine was added to cut-off summary text on a space rather than splitting a word in the middle. 

A simple Regular Expression is used to strip out HTML and a character array is used to find a good place to break-up the text for the summary.  The modified code is shown next:

public string FixDesc(object desc, object link)
{
    
if (link == null || desc == nullreturn String.Empty;

    string 
description desc.ToString();
    
//Replace all HTML tags so none get cut-off and screw up the page
    
Regex reg = new Regex("<.*?>",RegexOptions.Compiled);
    string 
stripDesc reg.Replace(description, String.Empty);
    if 
(stripDesc.Length > 250)
    {
        
int startPos 250;
        char
[] chars stripDesc.ToCharArray();
        char 
chars[startPos];
        while 
(!Char.IsWhiteSpace(c) && startPos < chars.Length)
        {
            startPos++
;
            
chars[startPos];
        
}
        stripDesc 
= new String(chars,0,startPos) + " ... <a href='" + link.ToString() + "'> More</a>";

    
}
    
return stripDesc;
}


The user control code that calls the FixDesc() method is shown here:

<asp:DataList ID="DataList1" runat="server" 
  DataSourceID
="odsRss" HorizontalAlign="Left" RepeatLayout="Flow">
   
<HeaderTemplate>
   
<p><a href="http://blogs.interfacett.com">
       (View All Instructor Blogs)
</a><br />
      </
HeaderTemplate>
    
<ItemTemplate>
        
<strong><a href='<%# Eval("Link") %>'><%# Eval("Title") %></a>
          
<br />
          
<%# Eval("PubDate") %> By <%# Eval("AuthorName") %></strong>
          
</p>
          
<p>
          
<%# FixDesc(Eval("Description"), Eval("Link"))%>
        
<br />     
    </
ItemTemplate>
    
<FooterTemplate>
    
</p>
    
</FooterTemplate>  
</asp:DataList>


The updated code can be found at the URL below:

http://www.xmlforasp.net/CodeBank/Download/Blog/BlogRollerWebsite.zip

 

Share this post: Email it! | bookmark it! | digg it! | reddit!

Read comments or post a reply to : RSS Blog Roller Code Update
Page 1739 of 1924
Next | Last

.NET News Categories








Legend : - Within 3 Days - Within 6 Days - Within 9 Days

Home | Add Resources | Sponsored Listings | Advertise with Us | SiteMap 1 | SiteMap 2 | Link To Us | Contact Us
© 2002-2008 Worldofasp.net ASP.NET Directory, Hosting and Tutorials | All rights reserved
Our Partners : ASP.NET Web Hosting | Windows Web Hosting | ASP.NET Hosting | Phone Card | PHP Directory | Bangkok Hotels |Calling Card