<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/c4f.Rohan-Singh/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/c4f.Rohan-Singh/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/c4f.Rohan-Singh/Posts</link>
    <language>en</language>
    <pubDate>Thu, 23 May 2013 15:40:24 GMT</pubDate>
    <lastBuildDate>Thu, 23 May 2013 15:40:24 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>1</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Building a Windows Vista Email Gadget using the .NET Framework</title>
      <description><![CDATA[<span id="c4fmetadata">
<table class="" cellspacing="0" cellpadding="1" width="100%" border="0">
<tbody>
<tr class="entry_overview">
<td class="" width="50">
<p>&nbsp;</p>
<p><img height="50" src="http://blogs.msdn.com/photos/coding4fun/images/1055021/original.aspx" width="62"></p>
</td>
<td class=""><span class="entry_description"><br>
<br>
The E-mail Alert Gadget is a simple yet indispensible Gadget for the Windows Sidebar platform. It provides users with a dynamic unread e-mail counter in the Windows Sidebar. By leveraging the convenience and functionality of Windows Sidebar and the power of
 .NET Framework applications, E-mail Alert is able to provide users with quick access to a useful piece of information: the number of unread e-mails in the user's inbox.</span></td>
</tr>
<tr>
<td class="" colspan="2">
<div class="entry_author">Rohan Singh</div>
<div class="entry_company"><a href="http://www.sharplogic.com/">SharpLogic Software</a></div>
<br>
<div class="entry_details"><b>Difficulty: </b><span class="entry_details_input">Easy</span></div>
<div class="entry_details"><b>Time Required:</b> <span class="entry_details_input">
1-3 hours</span></div>
<div class="entry_details"><b>Cost: </b><span class="entry_details_input">Free</span></div>
<div class="entry_details"><b>Software: </b><span class="entry_details_input">Tested on Windows Vista Beta 2 (Build 5384),
<a href="http://msdn.com/express/">Visual Basic or Visual C# Express Editions</a>,
<a href="http://msdn.microsoft.com/vstudio/express/vwd/">Visual Web Developer Express</a> for JavaScript editing.</span></div>
<div class="entry_details"><b>Hardware: </b><span class="entry_details_input">None</span></div>
<div class="entry_details"><b>Download: </b><a href="http://channel9.msdn.com/ShowPost.aspx?PostID=255919">Download</a>
<ul>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</span>
<p>&nbsp;</p>
<h3><strong></strong>&nbsp;&nbsp; </h3>
<h3><strong>Windows Sidebar</strong></h3>
<p>Windows Sidebar is an application host of sorts that enables you to host customizable mini-applications or “Gadgets” to boost your personal productivity. Windows Sidebar is supported on
<strike>both Windows XP</strike><strong>*</strong> and Windows Vista. Figure 1 shows a Sidebar with three Gadgets: a clock, a stock ticker, and a CPU and memory gauge.
</p>
<p>* Sidebar is not supported in Windows XP (thank you to alert C4F reader Tom Sage for pointing this out)&nbsp;
</p>
<p><a></a><a>Figure </a>1: Windows Sidebar. </p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image0026.jpg"><img height="468" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image002_thumb2.jpg" width="149" border="0"></a>
</p>
<h3>Windows Sidebar Gadgets </h3>
<p>Windows Sidebar Gadgets consist of, at the least, an HTML file containing the Gadget, an XML file describing the Gadget, and an icon for the Gadget. More functionality can be added through JavaScript and additional HTML. Moreover, the
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sidebar/sidebar/reference/refs.asp">
Windows Sidebar API</a> provides additional namespaces and functionality programmable through either VBScript or JavaScript for more dynamic Gadget functionality. In fact, using only JavaScript a Gadget can access the hard drive, check power and network status,
 read and write environment variables, and even communicate with Windows SideShow information appliances, and more.
</p>
<h3>E-mail Alert Gadget</h3>
<p>The E-mail Alert is a Gadget for Windows Sidebar that provides Microsoft Office Outlook and MSN Messenger users an at-a-glance count of the unread e-mails in their Outlook or Hotmail inbox. E-mail Alert also provides links that enable users to quickly access
 the inbox or compose a new message with the default e-mail application. </p>
<p>Like other Gadgets, E-mail Alert has been built with HTML and JavaScript. E-mail Alert can either be docked in the Sidebar or float on the Windows desktop. Unlike other Gadgets, the E-mail Alert Gadget shows how you can interoperate with a .NET external
 application so that you can harness the power of .NET applications in your Gadget.
</p>
<p><a href="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image0043.jpg"><img height="96" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image004_thumb1.jpg" width="125" border="0"></a>
</p>
<p>Figure 2: E-mail Alert Gadget. </p>
<h3>Connecting a Gadget to a .NET application</h3>
<p>Although it is generally recommended that Gadgets perform all of their logic in JavaScript whenever possible, there are occasionally times when it is beneficial to leverage external applications and scripts. In this sample we have opted to use the more complex
 external application model in order to illustrate a simple solution to connect a Gadget to a .NET application. In the case of the E-mail Alert Gadget, the
<b>GetUnreadEmailCount</b> application retrieves the user's current unread e-mail count. The application can then return output to the Gadget, which displays it to the user in the Sidebar.
</p>
<p>Figure 3: Gadget execution. </p>
<p><img height="244" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image0064.gif" width="366">
</p>
<h3>E-mail Alert Gadget Files</h3>
<p>The simplest Gadget consists of a single XML file describing the Gadget, an HTML file containing the entire Gadget, and a single PNG icon image for the Gadget. In order to incorporate more advanced functionality and design, a Gadget can also incorporate
 JavaScript, CSS, JScript, VBScript, or external executables. </p>
<h3>&nbsp;</h3>
<h3>Gadget.xml</h3>
<p><b>Gadget.xml</b> is the Gadget manifest, an XML file defining the Gadget's properties, including name, author, and description:
</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">name</span><span class="kwrd">&gt;</span>E-mail Alert<span class="kwrd">&lt;/</span><span class="html">name</span><span class="kwrd">&gt;</span> 

<span class="kwrd">&lt;</span><span class="html">author</span><span class="kwrd">&gt;</span>Microsoft Corporation<span class="kwrd">&lt;/</span><span class="html">author</span><span class="kwrd">&gt;</span> 

<span class="kwrd">&lt;</span><span class="html">copyright</span><span class="kwrd">&gt;</span>Microsoft 1985-2006<span class="kwrd">&lt;/</span><span class="html">copyright</span><span class="kwrd">&gt;</span> 

<span class="kwrd">&lt;</span><span class="html">description</span><span class="kwrd">&gt;</span>Keep up with new e-mail as you receive it.<span class="kwrd">&lt;/</span><span class="html">description</span><span class="kwrd">&gt;</span> 

</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>The information in the manifest is displayed to users when they are browsing available Gadgets through Windows Sidebar. The manifest also informs the Sidebar about which HTML file in the Gadget package contains the body of the Gadget, and contains information
 about icons to use for the Gadget. </p>
<h3>Email.html</h3>
<p><b>Email.html</b> is the main body of the E-mail Alert Gadget. Essentially, a Gadget is a collection of HTML and JavaScript that is displayed in the Windows Sidebar.
<b>Email.html</b> contains a link to a CSS file that provides style information for the Gadget. It also includes a link to
<b>Email.js</b>, a JavaScript file that is responsible for the functionality of the Gadget.
</p>
<h3>Email.js</h3>
<p><b>Email.js</b> is a JavaScript file that contains the main functionality of the E-mail Alert Gadget. When the Gadget first loads,
<b>Email.js </b>constructs a WScript Shell object. The WScript Shell object enables access to system information, environment variables, and the Windows Registry.
<b>Email.js</b> uses this object to search the registry to determine the user's e-mail client in the
<b>SetMailClientPath</b> method: </p>
<pre class="csharpcode">&nbsp;</pre>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Determine the name and path of the user's e-mail client.</span>
<span class="rem">/// &lt;/summary&gt;</span>

<span class="kwrd">function</span> SetMailClientPath()
{
    <span class="rem">// The name of the mail client should be the default</span>
    <span class="rem">// value for the mail count registry key. Retrieve it</span>
    <span class="rem">// using the WScript shell.</span>

    <span class="kwrd">try</span>
    {
        _MailClientName = _WshShell.RegRead(<span class="str">&quot;HKCU&quot;</span> &#43;
          _MailCountRegistryPath);
    }
    <span class="kwrd">catch</span> (e)
    {
        <span class="rem">// There is no mail client setting for this user,</span>
        <span class="rem">// fall back to the system default in HKLM.</span>
        _MailClientName = _WshShell.RegRead(<span class="str">&quot;HKLM&quot;</span> &#43;
          _MailCountRegistryPath);
    }
</pre>
<pre class="csharpcode">    <span class="rem">// Retrieve the path to the mail client using the</span>
    <span class="rem">// WScript shell.</span>
    <span class="kwrd">try</span>
    {
        _MailClientPath = _WshShell.RegRead(<span class="str">&quot;HKCU&quot;</span> &#43;
          _MailCountRegistryPath &#43; _MailClientName &#43;
          <span class="str">&quot;\\shell\\open\\command\\&quot;);
    }
    catch (e)
    {
        // There is no mail client path setting for this
        // user, fall back to the system default in HKLM.
        _MailClientPath = _WshShell.RegRead(&quot;</span>HKLM<span class="str">&quot; &#43;
          _MailCountRegistryPath &#43; _MailClientName &#43;
          &quot;</span>\\shell\\open\\command\\&quot;);
    } 
}
</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<pre class="csharpcode">&nbsp;</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>After determining the name and path of the user's e-mail client, <b>Email.js</b> enables a timer with an interval of 30 seconds. When the timer fires,
<b>Email.js</b> executes the <b>GetUnreadEmailCount</b> .NET application, passing the user's e-mail client preference as a command-line argument. Finally,
<b>Email.js</b> reads the number of unread e-mails from the standard output stream of the
<b>GetUnreadEmailCount</b> application and updates the E-mail Alert Gadget's display:
</p>
<h6></h6>
<h6>&nbsp;</h6>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Retrieve the unread mail count from the GetUnreadMailCount application.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">function</span> RefreshEmail()
{
    <span class="kwrd">try</span>
    {
        <span class="rem">// Stop the timer while we're retrieving data.</span>
        ClearRefreshIntervals();
    
        <span class="rem">// Run the GetUnreadMailCount application using the</span>
        <span class="rem">// WScript shell.</span>
        exec = _WshShell.Exec(<span class="str">&quot;\&quot;&quot;</span> &#43;
            window.external.System.Shell.GadgetPath &#43;
            <span class="str">&quot;\\&quot; &#43; _MailCountApplicationName &#43; &quot;</span>\<span class="str">&quot; \&quot;&quot;</span> &#43;
            _MailClientName &#43; <span class="str">&quot;\&quot;&quot;</span>);
            
        <span class="rem">// Grab the unread count from the standard output</span>
        <span class="rem">// stream of GetUnreadMailCount.</span>
        _UnreadEmailCount = exec.StdOut.ReadAll();
      
        <span class="rem">// Update the Gadget UI.</span>
        UpdateView();
        
        <span class="rem">// Restart the timer.</span>
        SetRefreshIntervals();     
    }
    <span class="kwrd">catch</span> (e)
    {
        <span class="rem">// An error occurred, display it and restart the</span>
        <span class="rem">// timer.</span>
        DisplayErrorMessage(_errEmailErrorText);
        SetRefreshIntervals();
    }

}

</pre>
<h3>GetUnreadEmailCount</h3>
<p><b>The GetUnreadEmailCount</b> .NET application is a simple application that accepts an e-mail client name as a command-line argument and determines the number of unread e-mails for that e-mail client. Currently,
<b>GetUnreadEmailCount</b> supports Microsoft Office Outlook and Windows Live Messenger (MSN Messenger). When
<b>GetUnreadEmailCount</b> does not recognize the requested e-mail client, it defaults to the unread e-mail count provided by the HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\UnreadMail registry key.
</p>
<p>Integration with Microsoft Office Outlook is achieved through the Microsoft Outlook 11.0 Object Library (the Outlook 11 Primary Interop Assembly), accessible through the
<b>Microsoft.Office.Interop.Outlook</b> namespace. <b>GetUnreadEmailCount</b> includes a shared function (static method) that retrieves the number of unread e-mails in the user's Microsoft Office Outlook by using the Messaging API (MAPI) support built into
 the Microsoft Outlook 11.0 library: </p>
<p>Visual Basic </p>
<pre class="csharpcode"><span class="rem">''' &lt;summary&gt;</span>
<span class="rem">''' Gets the number of unread messages in the user's Microsoft Office Outlook</span>
<span class="rem">''' inbox.</span>
<span class="rem">''' &lt;/summary&gt;</span>
<span class="rem">''' &lt;returns&gt;</span>
<span class="rem">''' Returns the number of unread messages in the user's</span>
<span class="rem">''' inbox.</span>
<span class="rem">''' &lt;/returns&gt;</span>
<span class="rem">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
<span class="kwrd">Private</span> <span class="kwrd">Shared</span> <span class="kwrd">Function</span> GetOutlookUnreadCount() <span class="kwrd">As</span> <span class="kwrd">Integer</span>
     <span class="rem">' Create a new reference to Office Outlook using</span>
     <span class="rem">' Messaging API (MAPI).</span>
     <span class="kwrd">Dim</span> outlookApplication <span class="kwrd">As</span> <span class="kwrd">New</span> Application()
     <span class="kwrd">Dim</span> outlookMapi <span class="kwrd">As</span> _NameSpace = _
          outlookApplication.GetNamespace(<span class="str">&quot;MAPI&quot;</span>)

     <span class="rem">' Logon to the user's Office Outlook inbox using MAPI</span>
     <span class="rem">' and default settings.</span>

     outlookMapi.Logon(<span class="kwrd">Nothing</span>, <span class="kwrd">Nothing</span>, <span class="kwrd">True</span>, <span class="kwrd">False</span>)

     <span class="rem">' Get and return the unread e-mail count from the</span>
     <span class="rem">' user's Office Outlook inbox.</span>

     <span class="kwrd">Return</span> _
          outlookMapi.GetDefaultFolder( _
          OlDefaultFolders.olFolderInbox).UnReadItemCount
<span class="kwrd">End</span> <span class="kwrd">Function</span>
</pre>
<p>C# </p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Gets the number of unread messages in the user's Microsoft Office Outlook</span>
<span class="rem">/// inbox.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;returns&gt;</span>
<span class="rem">/// Returns the number of unread messages in the user's inbox.</span>
<span class="rem">/// &lt;/returns&gt;</span>
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">int</span> GetOutlookUnreadCount()
{
     <span class="rem">// Create a new reference to Office Outlook using</span>
     <span class="rem">// Messaging API (MAPI).</span>
     Application outlookApplication = <span class="kwrd">new</span> Application();
     _NameSpace outlookMapi = outlookApplication
          .GetNamespace(<span class="str">&quot;MAPI&quot;</span>);

     <span class="rem">// Logon to the user's Office Outlook inbox using MAPI    // and default settings.</span>
     outlookMapi.Logon(<span class="kwrd">null</span>, <span class="kwrd">null</span>, <span class="kwrd">true</span>, <span class="kwrd">false</span>);

     <span class="rem">// Get and return the unread e-mail count from the   // user's Office Outlook inbox.</span>
     Return outlookMapi.GetDefaultFolder(
          OlDefaultFolders.olFolderInbox).UnReadItemCount;
}

</pre>
<p>For Windows Live Messenger, as well as for unrecognized e-mail clients, <b>GetUnreadEmailCount</b> falls back to the UnreadMail key in the registry. It accesses this using the
<b>Microsoft.Win32</b> namespace: </p>
<p>Visual Basic </p>
<pre class="csharpcode"><span class="rem">''' &lt;summary&gt;</span>
<span class="rem">''' Gets the number of unread messages listed in the user's registry.</span>
<span class="rem">''' &lt;/summary&gt;</span>
<span class="rem">''' &lt;returns&gt;</span>
<span class="rem">''' Returns the number of unread messages listed in the user's registry.</span>
<span class="rem">''' &lt;/returns&gt;</span>
<span class="rem">''' &lt;remarks&gt;&lt;/remarks&gt;</span>
<span class="kwrd">Private</span> <span class="kwrd">Shared</span> <span class="kwrd">Function</span> GetRegistryUnreadCount() <span class="kwrd">As</span> <span class="kwrd">Integer</span>
     <span class="rem">' Open the UnreadMail key in the registry that</span>
     <span class="rem">' contains unread e-mail counts.</span>
     Using unreadMailKey <span class="kwrd">As</span> RegistryKey = _
          Registry.CurrentUser.OpenSubKey( _
          <span class="str">&quot;SOFTWARE\Microsoft\Windows\&quot;</span> &amp; _
          <span class="str">&quot;CurrentVersion\UnreadMail&quot;</span>)
          <span class="kwrd">Dim</span> unreadEmailCount <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0
 
          <span class="rem">' The UnreadMail key in the registry contains</span>
          <span class="rem">' subkeys for each e-mail account. We'll iterate</span>
          <span class="rem">' through them and sum the unread e-mail counts.</span>
          <span class="kwrd">For</span> <span class="kwrd">Each</span> account <span class="kwrd">As</span> <span class="kwrd">String</span> <span class="kwrd">In</span> _
              unreadMailKey.GetSubKeyNames()
              unreadEmailCount &#43;=Int32.Parse( _
                   unreadMailKey.OpenSubKey(account) _
                   .GetValue(<span class="str">&quot;MessageCount&quot;</span>).ToString())
          <span class="kwrd">Next</span>
 
          <span class="kwrd">Return</span> unreadEmailCount
     <span class="kwrd">End</span> Using
<span class="kwrd">End</span> <span class="kwrd">Function</span>

</pre>
<p>C# </p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Gets the number of unread messages listed in the user's registry.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;returns&gt;</span>
<span class="rem">/// Returns the number of unread messages listed in the user's registry.</span>
<span class="rem">/// &lt;/returns&gt;</span>
<span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">int</span> GetRegistryUnreadCount()
{ 
     <span class="rem">// Open the UnreadMail key in the registry that</span>
     <span class="rem">// contains unread e-mail counts.</span>
     <span class="kwrd">using</span> (RegistryKey unreadMailKey = Registry
          .CurrentUser.OpenSubKey(
          <span class="str">@&quot;SOFTWARE\Microsoft\Windows\&quot; &#43;
          @&quot;</span>CurrentVersion\UnreadMail<span class="str">&quot;))
     {
          int unreadEmailCount = 0;
 
          // The UnreadMail key in the registry contains
          // subkeys for each e-mail account. We'll iterate
          // through them and sum the unread e-mail counts.
          foreach (string account in
              unreadMailKey.GetSubKeyNames())
          {
              unreadEmailCount &#43;= Int32.Parse(
                   unreadMailKey.OpenSubKey(account)
                   .GetValue(&quot;</span>MessageCount&quot;).ToString());
          }

          <span class="kwrd">return</span> unreadEmailCount;
     }
}

</pre>
<style type="text/css">
<!--
.csharpcode, .csharpcode 
	{font-size:small;
	color:black;
	font-family:consolas,"Courier New",courier,monospace;
	background-color:#ffffff}
.csharpcode 
	{margin:0em}
.csharpcode .rem
	{color:#008000}
.csharpcode .kwrd
	{color:#0000ff}
.csharpcode .str
	{color:#006080}
.csharpcode .op
	{color:#0000c0}
.csharpcode .preproc
	{color:#cc6633}
.csharpcode .asp
	{background-color:#ffff00}
.csharpcode .html
	{color:#800000}
.csharpcode .attr
	{color:#ff0000}
.csharpcode .alt
	{background-color:#f4f4f4;
	width:100%;
	margin:0em}
.csharpcode .lnum
	{color:#606060}
-->
</style>
<p>Once the number of unread e-mails has been determined, <b>GetUnreadEmailCount</b> writes its results to the standard output stream.
<b>Email.js</b> reads this stream and displays the number of unread e-mails in the Email Alert Gadget.
</p>
<p><img height="222" src="http://ecn.channel9.msdn.com/o9/c4fcontent/migration/1055051/image0088.jpg" width="407" border="0">
</p>
<h3>Packaging &amp; Deployment</h3>
<p>To Package a Gadget for deployment first, place any culture specific files, such as
<b>Gadget.xml</b>, into culture-specific folders. For the E-mail Alert Gadget, we can place
<b>Email.html</b>, <b>Gadget.xml</b>, and other culture-specific files in the <b>
en-US</b> folder. Non-culture-specific files remain outside of this folder. </p>
<p>To create a Gadget package, we first compress all the files and folders comprising the Gadget into a ZIP file, in this case
<b>Email&nbsp;Alert.zip</b>. Next, we replace the <b>.zip</b> file extension with the <b>
.gadget</b> file extension, yielding <b>Email&nbsp;Alert.gadget</b>. We can then deploy the Gadget file to a website or to the Microsoft Gadgets Gallery at
<b>microsoftgadgets.com</b>. </p>
<p>Windows Vista users can add the E-mail Alert Gadget to the Windows Sidebar simply by downloading and opening it. Since the entire Gadget is self-contained in the
<b>Email&nbsp;Alert.gadget</b> file, the E-mail Alert Gadget functions out-of-the-box with no configuration required.
</p>
<p>Figure 4: Installing the E-mail Alert Gadget. </p>
<h3>Conclusion</h3>
<p>The E-mail Alert Gadget demonstrates how you can extend Windows Sidebar Gadgets by interoperating with a .NET application, in this case to display an unread e-mail counter. This enables .NET developers to bridge the gap between JavaScript Gadgets and existing
 .NET applications. </p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://msdn.microsoft.com/library/en-us/sidebar/sidebar/overviews/gdo.asp">Windows Sidebar Gadget Development Overview</a>
</li><li><a href="http://msdn.microsoft.com/library/en-us/sidebar/sidebar/reference/refs.asp">Windows Sidebar Reference</a><br>
</li></ul>
<h3>Rohan Singh</h3>
<p>Rohan Singh, a software design engineer at SharpLogic Software, has been doing software Web development work for the past six years. Though now primarily a .NET developer, he has experience with web design, network administration, and server deployment.
 His current technological interests include Ajax, Windows Communication Foundation, and neural networks. While not at his keyboard, Rohan is an avid rock climber and snowboarder.</p>
 <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/c4f.Rohan-Singh/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:209305fc59e44bd79efe9e7600d899fc">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Building-a-Windows-Vista-Email-Gadget-using-the-NET-Framework</comments>
      <itunes:summary>




&amp;nbsp; 
 



The E-mail Alert Gadget is a simple yet indispensible Gadget for the Windows Sidebar platform. It provides users with a dynamic unread e-mail counter in the Windows Sidebar. By leveraging the convenience and functionality of Windows Sidebar and the power of
 .NET Framework applications, E-mail Alert is able to provide users with quick access to a useful piece of information: the number of unread e-mails in the user&#39;s inbox.



Rohan Singh
SharpLogic Software

Difficulty: Easy
Time Required: 
1-3 hours
Cost: Free
Software: Tested on Windows Vista Beta 2 (Build 5384),
Visual Basic or Visual C# Express Editions,
Visual Web Developer Express for JavaScript editing.
Hardware: None
Download: Download








&amp;nbsp; 
&amp;nbsp;&amp;nbsp; 
Windows Sidebar
Windows Sidebar is an application host of sorts that enables you to host customizable mini-applications or “Gadgets” to boost your personal productivity. Windows Sidebar is supported on
both Windows XP* and Windows Vista. Figure 1 shows a Sidebar with three Gadgets: a clock, a stock ticker, and a CPU and memory gauge.
 
* Sidebar is not supported in Windows XP (thank you to alert C4F reader Tom Sage for pointing this out)&amp;nbsp;
 
Figure 1: Windows Sidebar.  

 
Windows Sidebar Gadgets 
Windows Sidebar Gadgets consist of, at the least, an HTML file containing the Gadget, an XML file describing the Gadget, and an icon for the Gadget. More functionality can be added through JavaScript and additional HTML. Moreover, the

Windows Sidebar API provides additional namespaces and functionality programmable through either VBScript or JavaScript for more dynamic Gadget functionality. In fact, using only JavaScript a Gadget can access the hard drive, check power and network status,
 read and write environment variables, and even communicate with Windows SideShow information appliances, and more.
 
E-mail Alert Gadget
The E-mail Alert is a Gadget for Windows Sidebar that provides Microsoft Office Outlook and MSN Messenger use</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Building-a-Windows-Vista-Email-Gadget-using-the-NET-Framework</link>
      <pubDate>Fri, 10 Nov 2006 16:17:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Building-a-Windows-Vista-Email-Gadget-using-the-NET-Framework</guid>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1055051_100.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ecn.channel9.msdn.com/o9/c4f/images/1055051_220.jpg" height="165" width="220"></media:thumbnail>      
      <dc:creator>Rohan Singh</dc:creator>
      <itunes:author>Rohan Singh</itunes:author>
      <slash:comments>8</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Building-a-Windows-Vista-Email-Gadget-using-the-NET-Framework/RSS</wfw:commentRss>
      <category>Productivity</category>
      <category>Windows</category>
    </item>    
</channel>
</rss>