<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jesal gadhia &#187; c#</title>
	<atom:link href="http://jesal.us/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 05:32:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to parse Wordpress RSS feed using LINQ</title>
		<link>http://jesal.us/2010/03/how-to-parse-wordpress-rss-feed-using-linq/</link>
		<comments>http://jesal.us/2010/03/how-to-parse-wordpress-rss-feed-using-linq/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 05:32:28 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://jesal.us/?p=238</guid>
		<description><![CDATA[Here&#8217;s a code snippet of parsing a typical Wordpress RSS feed using LINQ. Note, we have to skip the first image from the media element since that&#8217;s usually a gravatar of the author.
Everything else is pretty straight forward.

    private void BindBlogFeed()
    {
        [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a code snippet of parsing a typical Wordpress RSS feed using LINQ. Note, we have to skip the first image from the media element since that&#8217;s usually a gravatar of the author.</p>
<p>Everything else is pretty straight forward.</p>
<pre>
    private void BindBlogFeed()
    {
        XDocument doc = XDocument.Load("http://blogworkseverytime.wordpress.com/feed/");
        XNamespace content = "http://purl.org/rss/1.0/modules/content/";
        XNamespace media = "http://search.yahoo.com/mrss/";

        var query = (from feed in doc.Descendants("item")
                     orderby DateTime.Parse(feed.Element("pubDate").Value) descending
                     select new
                     {
                         Title = feed.Element("title").Value,
                         Description = HttpUtility.HtmlDecode(feed.Element("description").Value),
                         Content = HttpUtility.HtmlDecode(feed.Element(content.GetName("encoded")).Value),
                         Image = (from img in feed.Elements(media.GetName("content"))
                                  where img.Attribute("url").Value.Contains("gravatar") == false
                                  select img.Attribute("url").Value).FirstOrDefault() ?? "",
                         Link = feed.Element("link").Value,
                         Date = DateTime.Parse(feed.Element("pubDate").Value).ToShortDateString()
                     });

        lvFirstBlogFeed.DataSource = query.Take(1).ToList();
        lvFirstBlogFeed.DataBind();

        lvRemainingBlogFeed.DataSource = query.Skip(1).ToList();
        lvRemainingBlogFeed.DataBind();
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2010/03/how-to-parse-wordpress-rss-feed-using-linq/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Parse Twitter Usernames, Hashtags and URLs in C# 3.0</title>
		<link>http://jesal.us/2009/05/how-to-parse-twitter-usernames-hashtags-and-urls-in-c-30/</link>
		<comments>http://jesal.us/2009/05/how-to-parse-twitter-usernames-hashtags-and-urls-in-c-30/#comments</comments>
		<pubDate>Wed, 06 May 2009 22:13:27 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=132</guid>
		<description><![CDATA[Lately I&#8217;ve been working on my pet project called Twime. So as part of that project, I wanted to add the ability to parse URLs, usernames and hashtags from the user&#8217;s Twitter timeline. Here&#8217;s how I went about doing that:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

public static class HTMLParser
{
    public static string Link(this [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on my pet project called <a href="http://jesal.us/twime/" target="_blank">Twime</a>. So as part of that project, I wanted to add the ability to parse URLs, usernames and hashtags from the user&#8217;s Twitter timeline. Here&#8217;s how I went about doing that:</p>
<pre name="code" class="c-sharp:nogutter;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

public static class HTMLParser
{
    public static string Link(this string s, string url)
    {
        return string.Format("&lt;a href=\"{0}\" target=\"_blank\"&gt;{1}&lt;/a&gt;", url, s);
    }
    public static string ParseURL(this string s)
    {
        return Regex.Replace(s, @"(http(s)?://)?([\w-]+\.)+[\w-]+(/\S\w[\w- ;,./?%&#038;=]\S*)?", new MatchEvaluator(HTMLParser.URL));
    }
    public static string ParseUsername(this string s)
    {
        return Regex.Replace(s, "(@)((?:[A-Za-z0-9-_]*))", new MatchEvaluator(HTMLParser.Username));
    }
    public static string ParseHashtag(this string s)
    {
        return Regex.Replace(s, "(#)((?:[A-Za-z0-9-_]*))", new MatchEvaluator(HTMLParser.Hashtag));
    }
    private static string Hashtag(Match m)
    {
        string x = m.ToString();
        string tag = x.Replace("#", "%23");
        return x.Link("http://search.twitter.com/search?q=" + tag);
    }
    private static string Username(Match m)
    {
        string x = m.ToString();
        string username = x.Replace("@", "");
        return x.Link("http://twitter.com/" + username);
    }
    private static string URL(Match m)
    {
        string x = m.ToString();
        return x.Link(x);
    }
}
</pre>
<p>So as you can see I&#8217;m using the new <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">Extension Methods</a> feature in C# 3.0.</p>
<p>Now I can simply just call the extension methods like this:</p>
<pre name="code" class="c-sharp:nogutter;">
string tweet = "Just blogged about how to parse HTML from the @twitter timeline - http://jesal.us/blog/?p=132 #programming";
Response.Write(tweet.ParseURL().ParseUsername().ParseHashtag());
</pre>
<p>and the result should looks something like this:</p>
<p>Just blogged about how to parse html from the <a href="http://twitter.com/twitter" target="_blank">@twitter</a> timeline &#8211; <a href="http://jesal.us/blog/?p=132" target="_blank">http://jesal.us/blog/?p=132</a> <a href="http://search.twitter.com/search?q=%23programming">#programming</a></p>
<p>Just be sure to call ParseURL method before ParseUsername and ParseHashtag. The other two methods will add URLs to the usernames and hastags and you don&#8217;t want ParseURL to confuse those links with the original links present in the text.</p>
<p>This was inspired by <a href="http://www.simonwhatley.co.uk/" target="_blank">Simon Whatley</a>&#8217;s <a href="http://www.simonwhatley.co.uk/parsing-twitter-usernames-hashtags-and-urls-with-javascript" target="_blank">post</a> about doing something similar using prototyping with JavaScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2009/05/how-to-parse-twitter-usernames-hashtags-and-urls-in-c-30/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Calculate Shipping Cost Using UPS OnLine Tools</title>
		<link>http://jesal.us/2009/02/calculate-shipping-cost-using-ups-webservice/</link>
		<comments>http://jesal.us/2009/02/calculate-shipping-cost-using-ups-webservice/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 05:46:39 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[shipping]]></category>
		<category><![CDATA[ups]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=101</guid>
		<description><![CDATA[Before using this code, all you need to do is register for an UPS OnLine Tools account and then apply for a XML Access key using your developer key which you will receive after creating an account. After you get your access key, just plug your username, password and the key into the highlighted line [...]]]></description>
			<content:encoded><![CDATA[<p>Before using this code, all you need to do is <a href="https://www.ups.com/one-to-one/register" target="_blank">register for an UPS OnLine Tools account</a> and then apply for a <a href="https://www.ups.com/e_comm_access/laServ?START_PAGE=INTRO&#038;CURRENT_PAGE=GET_ACCESS_KEY&#038;OPTION=ACCESS_LIC_XML&#038;loc=en_US" target="_blank">XML Access key</a> using your developer key which you will receive after creating an account. After you get your access key, just plug your username, password and the key into the highlighted line below and you should be good to go!</p>
<pre name="code" class="c-sharp:nogutter;highlight:[32]">
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;

/// <summary>
/// Summary description for ShippingCalculator
/// </summary>
namespace ad2.BusinessLogic
{
    public static class ShippingCalculator
    {
        public static decimal GetShippingCost(string shipFromZipCode, string shipToZipCode, string serviceRateCode, string packageWeight)
        {
            decimal shippingCost = -1;
            string URL = "https://www.ups.com/ups.app/xml/Rate";
            WebRequest objRequest = WebRequest.Create(URL);
            objRequest.Method = "POST";
            objRequest.ContentType = "application/x-www-form-urlencoded";

            using (StreamWriter writer = new StreamWriter(objRequest.GetRequestStream()))
            {
                writer.Write(GetAuthXML("accesskey", "username", "password"));
                writer.Write(GetRequestXML(shipFromZipCode, shipToZipCode, serviceRateCode, packageWeight));
                writer.Flush();
                writer.Close();
            }

            objRequest.Timeout = 5000;

            try
            {
                using (WebResponse objResponse = objRequest.GetResponse())
                {
                    XmlDocument xmlResponse = new XmlDocument();
                    xmlResponse.Load(objResponse.GetResponseStream());
                    int responseStatusCode = int.Parse(xmlResponse.SelectSingleNode("//RatingServiceSelectionResponse/Response/ResponseStatusCode").InnerText);

                    if (responseStatusCode == 1)
                    {
                        XmlNodeList xmlNodeList = xmlResponse.SelectNodes(string.Format("/RatingServiceSelectionResponse/RatedShipment/TotalCharges[../Service/Code={0}]/MonetaryValue", serviceRateCode));

                        foreach (XmlElement xmlElement in xmlNodeList)
                        {
                            shippingCost = decimal.Parse(xmlElement.InnerText);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ad2.ExceptionHandler.Log(ex);
            }

            return shippingCost;
        }
        private static string GetAuthXML(string accessLicenseNumber, string userID, string password)
        {
            StringBuilder xmlAuthTemplate = new StringBuilder();

            xmlAuthTemplate.Append("<?xml version="1.0"?>");
            xmlAuthTemplate.Append("<AccessRequest xml:lang="en-US">");
            xmlAuthTemplate.Append(string.Format("   <AccessLicenseNumber>{0}</AccessLicenseNumber>", accessLicenseNumber));
            xmlAuthTemplate.Append(string.Format("   <UserId>{0}</UserId>", userID));
            xmlAuthTemplate.Append(string.Format("   <Password>{0}</Password>", password));
            xmlAuthTemplate.Append("</AccessRequest>");
            xmlAuthTemplate.Append("<?xml version="1.0"?>");

            return xmlAuthTemplate.ToString();
        }
        private static string GetRequestXML(string shipFromZipCode, string shipToZipCode, string serviceRateCode, string packageWeight)
        {
            StringBuilder xmlRequestTemplate = new StringBuilder();

            xmlRequestTemplate.Append("<RatingServiceSelectionRequest xml:lang="en-US">");
            xmlRequestTemplate.Append("  <Request>");
            xmlRequestTemplate.Append("    <TransactionReference>");
            xmlRequestTemplate.Append("      <CustomerContext>Rating and Service</CustomerContext>");
            xmlRequestTemplate.Append("      <XpciVersion>1.0001</XpciVersion>");
            xmlRequestTemplate.Append("    </TransactionReference>");
            xmlRequestTemplate.Append("    <RequestAction>Rate</RequestAction>");
            xmlRequestTemplate.Append("    <RequestOption>shop</RequestOption>");
            xmlRequestTemplate.Append("  </Request>");
            xmlRequestTemplate.Append("  <PickupType>");
            xmlRequestTemplate.Append("  <Code>01</Code>");
            xmlRequestTemplate.Append("  </PickupType>");
            xmlRequestTemplate.Append("  <Shipment>");
            xmlRequestTemplate.Append("    <Shipper>");
            xmlRequestTemplate.Append("      <Address>");
            xmlRequestTemplate.Append(string.Format("    <PostalCode>{0}</PostalCode>", shipFromZipCode));
            xmlRequestTemplate.Append("      </Address>");
            xmlRequestTemplate.Append("    </Shipper>");
            xmlRequestTemplate.Append("    <ShipTo>");
            xmlRequestTemplate.Append("      <Address>");
            xmlRequestTemplate.Append(string.Format("    <PostalCode>{0}</PostalCode>", shipToZipCode));
            xmlRequestTemplate.Append("      </Address>");
            xmlRequestTemplate.Append("    </ShipTo>");
            xmlRequestTemplate.Append("    <Service>");
            xmlRequestTemplate.Append(string.Format("    <Code>{0}</Code>", serviceRateCode));
            xmlRequestTemplate.Append("    </Service>");
            xmlRequestTemplate.Append("    <Package>");
            xmlRequestTemplate.Append("      <PackagingType>");
            xmlRequestTemplate.Append("        <Code>02</Code>");
            xmlRequestTemplate.Append("        <Description>Package</Description>");
            xmlRequestTemplate.Append("      </PackagingType>");
            xmlRequestTemplate.Append("      <Description>Rate Shopping</Description>");
            xmlRequestTemplate.Append("      <PackageWeight>");
            xmlRequestTemplate.Append(string.Format("        <Weight>{0}</Weight>", packageWeight));
            xmlRequestTemplate.Append("      </PackageWeight>");
            xmlRequestTemplate.Append("     </Package>");
            xmlRequestTemplate.Append("    <ShipmentServiceOptions/>");
            xmlRequestTemplate.Append("  </Shipment>");
            xmlRequestTemplate.Append("</RatingServiceSelectionRequest>");
            xmlRequestTemplate.Append("</RatingServiceSelectionRequest>");

            return xmlRequestTemplate.ToString();
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2009/02/calculate-shipping-cost-using-ups-webservice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Clear All Items From Cache</title>
		<link>http://jesal.us/2008/09/how-to-clear-all-items-from-cache/</link>
		<comments>http://jesal.us/2008/09/how-to-clear-all-items-from-cache/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 23:00:50 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=94</guid>
		<description><![CDATA[
if (Cache.Count > 0)
{
	string currentKey = string.Empty;
	System.Collections.IDictionaryEnumerator cacheContents =
	System.Web.HttpContext.Current.Cache.GetEnumerator();

	Response.Write(string.Format("Following {0} cache keys were cleared:", Cache.Count));

	while (cacheContents.MoveNext())
	{
		currentKey = cacheContents.Key.ToString();
		Response.Write(currentKey + "");
		System.Web.HttpContext.Current.Cache.Remove(currentKey);
	}
}
else
{
	Response.Write("Nothing to clear. Cache is empty.");
}

]]></description>
			<content:encoded><![CDATA[<pre name="code" class="csharp:nogutter">
if (Cache.Count > 0)
{
	string currentKey = string.Empty;
	System.Collections.IDictionaryEnumerator cacheContents =
	System.Web.HttpContext.Current.Cache.GetEnumerator();

	Response.Write(string.Format("Following {0} cache keys were cleared:<br/><br/>", Cache.Count));

	while (cacheContents.MoveNext())
	{
		currentKey = cacheContents.Key.ToString();
		Response.Write(currentKey + "<br/>");
		System.Web.HttpContext.Current.Cache.Remove(currentKey);
	}
}
else
{
	Response.Write("Nothing to clear. Cache is empty.");
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/09/how-to-clear-all-items-from-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to easily parse HTML without RegEx</title>
		<link>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/</link>
		<comments>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/#comments</comments>
		<pubDate>Tue, 06 May 2008 16:50:04 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=91</guid>
		<description><![CDATA[I recently discovered an absolutely amazing HTML parsing library for .NET called HtmlAgilityPack. It completely takes away the pain of parsing complicated HTML with regular expressions.
Here&#8217;s a very simple example of what you could do with it &#8211; I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css class [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered an absolutely amazing HTML parsing library for .NET called <a href="http://www.codeplex.com/htmlagilitypack" target="_blank">HtmlAgilityPack</a>. It completely takes away the pain of parsing complicated HTML with regular expressions.</p>
<p>Here&#8217;s a very simple example of what you could do with it &#8211; I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css class called &#8220;scrape&#8221; assigned to it:<br />
<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">using</span> HtmlAgilityPack;

<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> _Default : System.Web.UI.Page
{
    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
    {
        HtmlDocument doc = <span class="kwrd">new</span> HtmlDocument();
        doc.Load(Server.MapPath(filePath));
        Parse(doc.DocumentNode);
    }
    <span class="kwrd">private</span> <span class="kwrd">void</span> Parse(HtmlNode n)
    {
        <span class="kwrd">foreach</span> (HtmlAttribute atr <span class="kwrd">in</span> n.Attributes)
        {
            <span class="kwrd">if</span> (atr.Name == <span class="str">"class"</span> &amp;&amp; atr.Value == <span class="str">"scrape"</span>)
            {
                Response.Write(n.InnerHtml);
            }
        }

        <span class="kwrd">if</span> (n.HasChildNodes)
        {
            <span class="kwrd">foreach</span> (HtmlNode cn <span class="kwrd">in</span> n.ChildNodes)
            {
                Parse(cn);
            }
        }
    }
}
</pre>
<p>
That&#8217;s just a very small part of what it could do. I&#8217;ll expand upon this and post a few more examples in the future showing some interesting things you could do with this. </p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Create A Random Fact Generator Using XML</title>
		<link>http://jesal.us/2008/04/how-to-create-a-random-fact-generator-using-xml/</link>
		<comments>http://jesal.us/2008/04/how-to-create-a-random-fact-generator-using-xml/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 00:03:19 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=90</guid>
		<description><![CDATA[This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.
XML: (Facts.xml)


&#60;?xml version="1.0" encoding="utf-8" ?&#62;
&#60;facts&#62;
  &#60;fact&#62;
    The numbers '172' can be found on the back [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple little random fact generator which will show a new fact every time the page loads. After the initial load it will store the XML in the cache until the file is changed again.</p>
<p><b>XML: (Facts.xml)</b></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">&lt;?</span><span class="html">xml</span> <span class="attr">version</span><span class="kwrd">="1.0"</span> <span class="attr">encoding</span><span class="kwrd">="utf-8"</span> ?<span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">facts</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    The numbers '172' can be found on the back of the U.S. $5 dollar
    bill in the bushes at the base of the Lincoln Memorial.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    President Kennedy was the fastest random speaker in the world
    with upwards of 350 words per minute.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    In the average lifetime, a person will walk the equivalent of 5
    times around the equator.
  <span class="kwrd">&lt;/</span><span class="html">fact</span><span class="kwrd">&gt;</span>
    .
    .
    .
<span class="kwrd">&lt;/</span><span class="html">facts</span><span class="kwrd">&gt;</span></pre>
<p><b>Code: (RandomFact.ascx.cs)</b></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">using</span> System;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Data;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Configuration;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Collections;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.Caching;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.Security;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.WebControls;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.WebControls.WebParts;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Web.UI.HtmlControls;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Xml;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.IO;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.ComponentModel;
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Drawing.Design;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_controls_RandomFact</span> : System.Web.UI.<span style="color: #2b91af;">UserControl</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">string</span> _xmlDataSource;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">UrlProperty</span>()]
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">string</span> XMLDataSource
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">get</span> { <span style="color: blue;">return</span> _xmlDataSource; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">set</span> { _xmlDataSource = <span style="color: blue;">value</span>; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; litFact.Text = getRandomFact();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">string</span> getRandomFact()
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Random</span> rndIndex = <span style="color: blue;">new</span> <span style="color: #2b91af;">Random</span>();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">XmlDocument</span> xmlDocFacts = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlDocument</span>();
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">string</span> strFact = <span style="color: blue;">string</span>.Empty;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">try</span>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (Cache[<span style="color: #a31515;">"xmlDocFacts"</span>] != <span style="color: blue;">null</span>)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlDocFacts = (<span style="color: #2b91af;">XmlDocument</span>)Cache[<span style="color: #a31515;">"xmlDocFacts"</span>];
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlDocFacts.Load(Server.MapPath(XMLDataSource));
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Cache.Insert(<span style="color: #a31515;">"xmlDocFacts"</span>, xmlDocFacts, <span style="color: blue;">new</span> <span style="color: #2b91af;">CacheDependency</span>(Server.MapPath(XMLDataSource)));
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">XmlNodeList</span> xmlNodesMessage = xmlDocFacts.SelectNodes(<span style="color: #a31515;">"//fact"</span>);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">int</span> rnd = rndIndex.Next(0, xmlNodesMessage.Count);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strFact = Server.HtmlEncode(xmlNodesMessage[rnd].InnerText);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strFact = <span style="color: blue;">string</span>.Format(<span style="color: #a31515;">"&lt;b&gt;Error:&lt;/b&gt; {0}"</span>, ex.Message);
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> strFact;
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p><b>Usage: (Default.aspx)</b><br />
<br/></p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: #a31515;">uc1</span><span style="color: blue;">:</span><span style="color: #a31515;">RandomFact</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;RandomFact1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">XMLDataSource</span><span style="color: blue;">=&#8221;App_Data/Facts.xml&#8221;</span> <span style="color: blue;">/&gt;</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/04/how-to-create-a-random-fact-generator-using-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to manipulate video in .NET using ffmpeg (updated)</title>
		<link>http://jesal.us/2008/04/how-to-manipulate-video-in-net-using-ffmpeg-updated/</link>
		<comments>http://jesal.us/2008/04/how-to-manipulate-video-in-net-using-ffmpeg-updated/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 18:25:55 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[ffmpeg]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=86</guid>
		<description><![CDATA[Based on the reader comments on my previous entry on this topic I was able to fix some of the issues that others were experiencing.
I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option [...]]]></description>
			<content:encoded><![CDATA[<p>Based on the reader comments on my <a href="http://www.calistomind.com/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/">previous entry</a> on this topic I was able to fix some of the issues that others were experiencing.</p>
<p>I changed how the output is read, instead of reading the entire stream at once, its now read line-by-line as ErrorDataReceived and OutputDataReceived events are raised. Also added an extra option in the command line (-ar 44100) to explicitly set the audio frequency to default since it wasn&#8217;t being applied to some video formats resulting in an error. And lastly, the console window is now set as hidden.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">void</span> ConvertVideo(<span class="kwrd">string</span> srcURL, <span class="kwrd">string</span> destURL)
{
    <span class="kwrd">string</span> ffmpegURL = “~/project/tools/ffmpeg.exe”;
    DirectoryInfo directoryInfo = <span class="kwrd">new</span> DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = <span class="kwrd">new</span> ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    startInfo.Arguments = <span class="kwrd">string</span>.Format(“-i \”{0}\” -aspect 1.7777 -ar 44100 -f flv \”{1}\”", srcURL, destURL);
    startInfo.WorkingDirectory = directoryInfo.FullName;
    startInfo.UseShellExecute = <span class="kwrd">false</span>;
    startInfo.RedirectStandardOutput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardInput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardError = <span class="kwrd">true</span>;
    startInfo.CreateNoWindow = <span class="kwrd">true</span>;
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;

    <span class="kwrd">using</span> (Process process = <span class="kwrd">new</span> Process())
    {
        process.StartInfo = startInfo;
        process.EnableRaisingEvents = <span class="kwrd">true</span>;
        process.ErrorDataReceived += <span class="kwrd">new</span> DataReceivedEventHandler(process_ErrorDataReceived);
        process.OutputDataReceived += <span class="kwrd">new</span> DataReceivedEventHandler(process_OutputDataReceived);
        process.Exited += <span class="kwrd">new</span> EventHandler(process_Exited);

        <span class="kwrd">try</span>
        {
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            process.WaitForExit();
        }
        <span class="kwrd">catch</span> (Exception ex)
        {
            lblError.Text = ex.ToString();
        }
        <span class="kwrd">finally</span>
        {
            process.ErrorDataReceived -= <span class="kwrd">new</span> DataReceivedEventHandler(process_ErrorDataReceived);
            process.OutputDataReceived -= <span class="kwrd">new</span> DataReceivedEventHandler(process_OutputDataReceived);
            process.Exited -= <span class="kwrd">new</span> EventHandler(process_Exited);
        }
    }
}
<span class="kwrd">void</span> process_OutputDataReceived(<span class="kwrd">object</span> sender, DataReceivedEventArgs e)
{
    <span class="kwrd">if</span> (e.Data != <span class="kwrd">null</span>)
    {
        lblStdout.Text += e.Data.ToString() + “&lt;br /&gt;”;
    }
}
<span class="kwrd">void</span> process_ErrorDataReceived(<span class="kwrd">object</span> sender, DataReceivedEventArgs e)
{
    <span class="kwrd">if</span> (e.Data != <span class="kwrd">null</span>)
    {
        lblStderr.Text += e.Data.ToString() + “&lt;br /&gt;”;
    }
}
<span class="kwrd">void</span> process_Exited(<span class="kwrd">object</span> sender, EventArgs e)
{
    <span class="rem">//Post-processing code goes here</span>
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/04/how-to-manipulate-video-in-net-using-ffmpeg-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to unzip files in .NET using SharpZipLib</title>
		<link>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/</link>
		<comments>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:30:22 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[sharpziplib]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/03/12/how-to-unzip-files-in-net-using-sharpziplib/</guid>
		<description><![CDATA[SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info &#8211; http://www.icsharpcode.net/OpenSource/SharpZipLib/
In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.


.
.
using System.IO;
using ICSharpCode.SharpZipLib.Zip
.
.
private void UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = new ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
 [...]]]></description>
			<content:encoded><![CDATA[<p>SharpZipLib is a great open source library for handeling all kinds of gzip/zip compression/decompression. More Info &#8211; <a href="http://www.icsharpcode.net/OpenSource/SharpZipLib/">http://www.icsharpcode.net/OpenSource/SharpZipLib/</a></p>
<p>In the following example I&#8217;m passing the HtmlInputFile object directly into the ZipInputStream to decompress the PostedFile and save its contents on the server.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
.
.
<span class="kwrd">using</span> System.IO;
<span class="kwrd">using</span> ICSharpCode.SharpZipLib.Zip
.
.
<span class="kwrd">private</span> <span class="kwrd">void</span> UnzipAndSave(HtmlInputFile objFileUpload)
{
    ZipInputStream s = <span class="kwrd">new</span> ZipInputStream(objFileUpload.PostedFile.InputStream);

    ZipEntry theEntry;
    <span class="kwrd">string</span> virtualPath = <span class="str">"~/uploads/"</span>;
    <span class="kwrd">string</span> fileName = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileExtension = <span class="kwrd">string</span>.Empty;
    <span class="kwrd">string</span> fileSize = <span class="kwrd">string</span>.Empty;

    <span class="kwrd">while</span> ((theEntry = s.GetNextEntry()) != <span class="kwrd">null</span>)
    {
        fileName = Path.GetFileName(theEntry.Name);
        fileExtension = Path.GetExtension(fileName);

        <span class="kwrd">if</span> (!<span class="kwrd">string</span>.IsNullOrEmpty(fileName))
        {
            <span class="kwrd">try</span>
            {
                FileStream streamWriter = File.Create(Server.MapPath(virtualPath + fileName));
                <span class="kwrd">int</span> size = 2048;
                <span class="kwrd">byte</span>[] data = <span class="kwrd">new</span> <span class="kwrd">byte</span>[2048];

                <span class="kwrd">do</span>
                {
                    size = s.Read(data, 0, data.Length);
                    streamWriter.Write(data, 0, size);
                } <span class="kwrd">while</span> (size &gt; 0);

                fileSize = Convert.ToDecimal(streamWriter.Length / 1024).ToString() + ” KB”;

                streamWriter.Close();

                <span class="rem">//Add custom code here to add each file to the DB, etc.</span>
            }
            <span class="kwrd">catch</span> (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }

    s.Close();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/03/how-to-unzip-files-in-net-using-sharpziplib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to manipulate video in .NET using ffmpeg</title>
		<link>http://jesal.us/2008/03/how-to-manipulate-video-in-net-using-ffmpeg/</link>
		<comments>http://jesal.us/2008/03/how-to-manipulate-video-in-net-using-ffmpeg/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:02:04 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[ffmpeg]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/03/12/how-to-manipulate-video-in-net-using-ffmpeg/</guid>
		<description><![CDATA[In this case I&#8217;m resizing the video and converting it to FLV format. For more ffmpeg commandline options - http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html


private void ConvertVideo(string srcURL, string destURL)
{
    string ffmpegURL = "~/project/tools/ffmpeg.exe";
    DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    [...]]]></description>
			<content:encoded><![CDATA[<p>In this case I&#8217;m resizing the video and converting it to FLV format. For more ffmpeg commandline options - <a href="http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html">http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html</a></p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">private</span> <span class="kwrd">void</span> ConvertVideo(<span class="kwrd">string</span> srcURL, <span class="kwrd">string</span> destURL)
{
    <span class="kwrd">string</span> ffmpegURL = <span class="str">"~/project/tools/ffmpeg.exe"</span>;
    DirectoryInfo directoryInfo = <span class="kwrd">new</span> DirectoryInfo(Path.GetDirectoryName(Server.MapPath(ffmpegURL)));

    ProcessStartInfo startInfo = <span class="kwrd">new</span> ProcessStartInfo();
    startInfo.FileName = Server.MapPath(ffmpegURL);
    startInfo.Arguments = <span class="kwrd">string</span>.Format(<span class="str">"-i \"{0}\" -s 368x216 -aspect 1.7777 \"{1}\""</span>, srcURL, destURL);
    startInfo.WorkingDirectory = directoryInfo.FullName;
    startInfo.UseShellExecute = <span class="kwrd">false</span>;
    startInfo.RedirectStandardOutput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardInput = <span class="kwrd">true</span>;
    startInfo.RedirectStandardError = <span class="kwrd">true</span>;

    <span class="kwrd">using</span> (Process process = <span class="kwrd">new</span> Process())
    {
        process.StartInfo = startInfo;

        <span class="kwrd">try</span>
        {
            process.Start();
            StreamReader standardOutput = process.StandardOutput;
            StreamWriter standardInput = process.StandardInput;
            StreamReader standardError = process.StandardError;
            process.WaitForExit();

            lblError.Text = standardError.ReadToEnd();
            lblOutput.Text = standardOutput.ReadToEnd();
        }
        <span class="kwrd">catch</span> (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/03/how-to-manipulate-video-in-net-using-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Event Driven Developement using ASP.NET &amp; C#</title>
		<link>http://jesal.us/2008/02/event-driven-developement-using-aspnet-c/</link>
		<comments>http://jesal.us/2008/02/event-driven-developement-using-aspnet-c/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 08:01:45 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/02/16/event-driven-developement-using-aspnet-c/</guid>
		<description><![CDATA[Until recently I wasn&#8217;t entirely familiar with the concepts of Event Driven Programming, Event Bubbling, etc. Being a .NET developer I&#8217;ve been exposed to events and delegates but I never really understood the concept in its entirety. Somehow I had a hard time readily finding good sources online focusing on event driven programming especially using [...]]]></description>
			<content:encoded><![CDATA[<p>Until recently I wasn&#8217;t entirely familiar with the concepts of <a href="http://en.wikipedia.org/wiki/Event-driven_programming" target="_blank">Event Driven Programming</a>, <a href="http://www.odetocode.com/Articles/94.aspx" target="_blank">Event Bubbling</a>, etc. Being a .NET developer I&#8217;ve been exposed to events and delegates but I never really understood the concept in its entirety. Somehow I had a hard time readily finding <strong>good</strong> sources online focusing on event driven programming especially using ASP.NET/C#.  But I had to get myself more familiarized with the concept since I need to use a lot of that in my current project. So after doing some digging I found couple of good links which explain the concept quite well -</p>
<ul>
<li><a href="http://www.akadia.com/services/dotnet_delegates_and_events.html" target="_blank">Delegates and Events in C# / .NET</a></li>
<li><a href="http://www.sitepoint.com/article/driven-asp-net-development-c" target="_blank">Event Driven ASP.NET Development with C#</a></li>
</ul>
<p>Hope that helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/02/event-driven-developement-using-aspnet-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
