Thursday, April 30, 2009

Gravatar using ASP.NET

I’m always attracted with the fancy features in web. This time, I fall in love with Gravatar. Its a global recognition of “YOU”, with the help of an e-mail Id.

If you don't have a Gravatar account, create on here.

The SRC attribute a Gravatar Image has the below mentioned syntax:

http://www.gravatar.com/avatar/[MD5_Hash_Value]?s=[Image_Size]

For loading your Gravatar image, all you’ve to do is to mention the Hash Value of your email id and the size of your Gravatar image.

Before start, drag-drop an Image control, TextBox (for accepting email Id) and Button control.

[Source-View]

   1: <body>
   2:     <form id="form1" runat="server">
   3:     <div>
   4:         <asp:Image ID="Image1" src="" runat="server" /><br />
   5:         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   6:         <asp:Button ID="Button1" runat="server" Text="Button" />
   7:     </div>
   8:     </form>
   9: </body>



[Code-View]





   1: // Page Load
   2: protected void Page_Load(object sender, EventArgs e)
   3: {
   4:     // Add SRC attribute to Iage1 at runtime
   5:     Image1.Attributes.Add("src", GetGravatarImageURL(TextBox1.Text.Trim(), 80));
   6: }
   7:  
   8: // Return Gravatar Image URL
   9: public static string GetGravatarImageURL(string emailId, int imgSize)
  10: {
  11:  
  12:     string hash = string.Empty;
  13:     string imageURL = string.Empty;
  14:  
  15:     // Convert emailID to lower-case
  16:     emailId = emailId.ToLower();
  17:  
  18:     hash = FormsAuthentication.HashPasswordForStoringInConfigFile(emailId, "MD5").ToLower();
  19:  
  20:     // build Gravatar Image URL
  21:     imageURL = "http://www.gravatar.com/avatar/" + hash + ".jpg?s=" + imgSize;
  22:  
  23:     return imageURL;
  24: }



Now just run/build(F5) your page. The image will looks like below:



noGravatar_Sample



This is the default Gravatar image.



noGravatar 



Now just, enter your email Id used for creating the Gravatar account. & hit the button.



Hurray you’re done. Just integrate at the comments section of your blog.





 myGravatar





This is my gravatar image



That's it & Thanks.

Saturday, April 25, 2009

Change GridView row values using RowUpdating event


The contents of this post has been moved to here. Please visit the link to view the contents.

Sorry for the inconvenience.

Thanks!

Wednesday, April 22, 2009

FF3 Ad over IE

Does anyone noticed this?

http://www.mozilla.com/en-US/firefox/ie.html

ff3_vs_ie8

See, the courage, confidence and power of Mozilla corporation; directly advertising over IE. Nothing to say more, IE market-share dipped to 66%. But, this time IE is losing the market-share in a quicker pace. IE8 have to struggle a lot to gain the market again and again.

Good luck, IE.

BTW, I’m an addicted IE user.

Thursday, April 2, 2009

Inserting selected attribute values into a Table

Just imagine you’ve five fields (columns) in table & you only want to insert 2 values (say, in Col2 & Col3) of the table; then use as follows:

   1: INSERT INTO Table_Name (Col2_Name, Col3_Name)
   2:     VALUES (Col2_Value, Col3_Value)

Wednesday, April 1, 2009

Programmatically accessing RSS Feed using RSSToolkit Control

An awesome RSS Feed control (Dmitry’s RSSToolkit) was released years before, I came to knew about ASP.NET.

Last months, I’s spending some time with the control.  I must say, its really cool. One problem I encountered; lack of documentation (or my lack of knowledge), What ever it may. But, it was really nice to write some cool codes using the control.

Ok! In this article, I’ll show small piece of codes demonstrating how to retrieve RSS Feeds from sites programmatically.

Before we start, please download RSSToolkit 2.0 from codeplex, and add the control to your Visual Studio toolbox (?).

Step 1: Drag-drop ‘RssDataSource’ control from your toolbox to the webpage.

Choose RSSDataSource

Now just keep an eye on the source-view. When you drag-drop the RssDataSource, you’ll get a Register tag in the source-view like:

<%@ Register assembly="RssToolkit" namespace="RssToolkit.Web.WebControls" tagprefix="cc1" %>

Step 2: Drag-drop a TextBox for  accepting the feed-url.

Step 3: Drag-drop a Button to trigger fetching the feeds. Double-Click the button to generate the Click event.

Step 4: Drag-drop a Label control to show an error when you enter an invalid feed-url.

[Design-View]

Design-View

[Source-View]

<body>
<form id="form1" runat="server">
<div>
<cc1:RssDataSource ID="RssDataSource1" runat="server">
</cc1:RssDataSource>
<br />
Enter Feed URL:
<asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Fetch" />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label>
</div>
</form>
</body>

[Code-View]

using RssToolkit.Rss;

// Fecth RSS
protected void Button1_Click(object sender, EventArgs e)
{
string feedData = string.Empty;
// Accepts Feed URL
RssDataSource1.Url = TextBox1.Text.Trim();

try
{
// Iterate through the RSS feed Items
foreach (RssItem item in RssDataSource1.Rss.Channel.Items)
{
// Feed Author
feedData = item.Author;
// Feed Title
feedData = item.Title;
// Feed Link
feedData = item.Link;
// Feed Description
feedData = item.Description;
// Feed Publish Date
feedData = item.PubDate;

// Print the output
Response.Write(feedData + "<br/><hr/><br/>");
}
}
catch (UriFormatException exp)
{
Label1.Text
= "Invalid Feed URL";
}
}

[Demonstration]
a) copy the url of an RSS feed, say http://feeds2.feedburner.com/DidYouSaynet.

b) Paste it on the TextBox & Hit the button. That's all.

c) See How the feeds are displayed.

Hoping it will help someone.

Note:

a) Do not forget to include the namespace using RSSToolkit.RSS.

b) One of the common question you may encounter is how to fetch feeds with a count limit?. That means you only want to fetch last 3 feeds, 5 feeds, etc. At this point I don't have the answer. Even though the RSSDataSource has a property named MaxItems ( where you can set the feed limit), it was not working when tried programmatically. Only way I believe you can do; is to insert a count value in the foreach statement  & break the loop when you feed-count limit is reached.

c) Next question will be how can I download updated feeds only from a site?. The answer will be my next post.

Also you can find some cool articles of RSSToolkit @ ScottGu’s blog and @ CodeProject, which inspired me to write this.

Thanks for taking time to read the post.

Adding Controls to Visual Studio Toolbox

 

The contents of this post has been moved to http://blogs.cametoofar.com/post/Adding-Controls-to-Visual-Studio-Toolbox.aspx.

Sorry for inconvenience.

Thanks

 
Best viewed in Internet Explorer 8.