tag:blogger.com,1999:blog-55999029973559133992024-02-08T01:21:13.401+00:00Random consultantRandom things I come across inside and outside of the IT world.SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-5599902997355913399.post-63693148271975739902017-01-17T15:20:00.000+00:002017-01-17T17:29:49.737+00:00Get your Raspberry PI to Read Out your Text Messages using IFTTT<div dir="ltr" style="text-align: left;" trbidi="on">
Continuing the theme of talking Raspberry Pi's from my recent posts (<a href="http://randomconsultant.blogspot.co.uk/2016/12/get-your-raspberry-pi-to-speak-news.html">Get your RPi to Speak the News</a> and <a href="http://randomconsultant.blogspot.co.uk/2017/01/building-amazon-echo-like-device-with.html">Turn your RPi into a Amazon Echo like device</a>), using the brilliant service <a href="https://ifttt.com/">IFTTT</a> (<b>I</b>f <b>T</b>his <b>T</b>hen <b>T</b>hat), I've created a way the my Raspberry Pi reads out a notification whenever I receive a SMS on my (android) mobile phone.<br />
<div>
<br /></div>
<div>
If you don't know what <a href="https://ifttt.com/">IFTTT </a>is, <a href="https://en.wikipedia.org/wiki/IFTTT">wikipedia </a>calls it :</div>
<div>
<br /></div>
<div>
<i>IFTTT is a free web-based service that allows users to create chains of simple conditional statements, called "applets", which are triggered based on changes to other web services such as Gmail, Facebook, Instagram, and Pinterest. IFTTT is an abbreviation of "If This Then That".</i></div>
<div>
<br /></div>
<div>
The below shows the sequence of events of how information regarding a SMS received on your phone ends up on the Raspberry Pi.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPqn37UCogEKhBOnbmMEhc0U4YXYu-YhM6KCTgdf402otygfx8pM7eRR16OQ77OGZ9qwbSdWrKYmESnjVMoFq1QkUUiUdH597EUiIyeXH-qbKq5HlVAHxFomX7Q1AUZrQqfRZfclIJft0/s1600/IFTTT+Rpi.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPqn37UCogEKhBOnbmMEhc0U4YXYu-YhM6KCTgdf402otygfx8pM7eRR16OQ77OGZ9qwbSdWrKYmESnjVMoFq1QkUUiUdH597EUiIyeXH-qbKq5HlVAHxFomX7Q1AUZrQqfRZfclIJft0/s640/IFTTT+Rpi.jpg" width="640" /></a></div>
<div>
<br /></div>
<div>
In IFTTT, you create an "applet", which fires a trigger when an SMS arrives on your phone, it then sends this info to the central IFTTT service which then performs an action you select. This action could be to turn on light using something like WeMo or Phillips Hue, or adding a row in a Google Sheet, or even sending a Gmail. But in this case the action is to send a webrequest to my raspberry pi. The web request is handled by some PHP code using <a href="http://www.w3schools.com/js/js_json_intro.asp">JSON </a>, which reads the info send and then executes<br />
<br />
<b>Please note I am using the <i>Android SMS </i>trigger on IFTTTT. There doesn't seem to be an equivalent for IPhones</b></div>
<div>
<br /></div>
<div>
So what do you need to set this up:</div>
<div>
<br /></div>
<div>
<b><u>1. Setup your Pi as a Webserver</u></b></div>
<div>
<br /></div>
<div>
The below 3 steps are covered on the site: <a href="http://www.penguintutor.com/linux/light-webserver">http://www.penguintutor.com/linux/light-webserver</a></div>
<div>
<ul style="text-align: left;">
<li>Raspberry Pi running a web server such as <a href="https://www.lighttpd.net/">lighttpd</a></li>
<li>Have a fixed IP or use a dynamic dns service such as <a href="http://noip.com/">noip.com</a> to you have a URL which connects to your Raspberry Pi . You may also need to setup your home router to forward incoming http requests to your Raspberry Pi</li>
<li>Install PHP to right server side code to handle IFTTT actions and/or to run other web applications you may want to write. </li>
</ul>
<div>
<b><u>2. Setup Script to execute Text to Speech </u></b></div>
<div>
<ul style="text-align: left;">
<li>Follow steps 1 and 2 on the following post I wrote to setup a script which uses the Google Translate service: </li>
<ul>
<li><a href="http://randomconsultant.blogspot.co.uk/2016/12/get-your-raspberry-pi-to-speak-news.html">http://randomconsultant.blogspot.co.uk/2016/12/get-your-raspberry-pi-to-speak-news.html</a></li>
</ul>
<li>You can download the bash script we will use from:</li>
<ul>
<li><a href="https://www.dropbox.com/s/d4ps0rveoo1p8an/speech.sh?dl=0">https://www.dropbox.com/s/d4ps0rveoo1p8an/speech.sh?dl=0</a></li>
</ul>
</ul>
</div>
<div>
<u><b>3. Setup PHP page to handle request</b> </u></div>
</div>
<div>
<br /></div>
<div>
<ul style="text-align: left;">
<li>Create a file readSMS.php in your /var/www directory (this is the default for lighttpd) with the following content :</li>
</ul>
<div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #557799;">
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #996633;">$_SERVER</span>[<span style="background-color: #fff0f0;">'REQUEST_METHOD'</span>] <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">'POST'</span>)
{
<span style="color: #996633;">$data</span> <span style="color: #333333;">=</span> <span style="color: #007020;">file_get_contents</span>(<span style="background-color: #fff0f0;">"php://input"</span>);
<span style="color: #888888;">//Removes all 3 types of line breaks</span>
<span style="color: #996633;">$data</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r</span><span style="background-color: #fff0f0;">"</span>, <span style="background-color: #fff0f0;">" "</span>, <span style="color: #996633;">$data</span>);
<span style="color: #996633;">$data</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\n</span><span style="background-color: #fff0f0;">"</span>, <span style="background-color: #fff0f0;">" "</span>, <span style="color: #996633;">$data</span>);
<span style="color: #996633;">$result</span> <span style="color: #333333;">=</span> <span style="color: #007020;">json_decode</span>(<span style="color: #996633;">$data</span>, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #996633;">$myfile</span> <span style="color: #333333;">=</span> <span style="color: #007020;">fopen</span>(<span style="background-color: #fff0f0;">"readSMStest.txt"</span>, <span style="background-color: #fff0f0;">"w"</span>) <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"Unable to open file!"</span>);
<span style="color: #007020;">fwrite</span>(<span style="color: #996633;">$myfile</span>, <span style="color: #996633;">$data</span>);
<span style="color: #996633;">$strText</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"SMS received from "</span> <span style="color: #333333;">.</span> <span style="color: #996633;">$result</span>[<span style="background-color: #fff0f0;">'contact'</span>];
<span style="color: #007020;">fwrite</span>(<span style="color: #996633;">$myfile</span>,"\n" .<span style="color: #996633;">$strText</span>);
<span style="color: #007020;">fclose</span>(<span style="color: #996633;">$myfile</span>);
<span style="color: #996633;">$strCommand</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"sudo /home/pi/Documents/speech.sh"</span> <span style="color: #333333;">.</span> <span style="background-color: #fff0f0;">" "</span> <span style="color: #333333;">.</span> <span style="color: #996633;">$strText</span> ;
<span style="color: #007020;">exec</span>(<span style="color: #996633;">$strCommand</span>, <span style="color: #996633;">$command_output</span>);
<span style="color: #008800; font-weight: bold;">foreach</span>(<span style="color: #996633;">$command_output</span> <span style="color: #008800; font-weight: bold;">as</span> <span style="color: #996633;">$line</span>) <span style="color: #333333;">:</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="color: #996633;">$line</span> ;
<span style="color: #008800; font-weight: bold;">endforeach</span>;
}
<span style="color: #333333;">?></span>
</span></pre>
</div>
<div>
<br /></div>
<ul style="text-align: left;">
<li>This code reads the input from an HTTP Post (we will setup IFTTT later to send an http post request) , decodes the JSON sent by IFTTT, and extracts the contact name of who sent the SMS to your phone. It then executes the speech.sh script which you should have set up from the previous step. </li>
<li>You may need to change the $strCommand string to the location of where you saved the speech.sh file</li>
<li>The script also for debugging purposed writes a text file readSMStest.txt to the same folder</li>
<li>The above can be downloaded from:</li>
<ul>
<li><a href="https://dl.dropboxusercontent.com/u/427946/Rpi%20Speech/readSMS.php">https://dl.dropboxusercontent.com/u/427946/Rpi%20Speech/readSMS.php</a></li>
</ul>
</ul>
<div>
<br /></div>
</div>
<div>
<b>4. Create Applet in IFTTT</b></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<ul style="text-align: left;">
<li>Sign up to <a href="https://ifttt.com/">IFTTT</a> and download the app to your phone </li>
<li>In the IFTTT site click on <i>My Applets</i> then on the <i>New Applet</i> button</li>
<li>You will see the below Applet Maker, click on the "+ this" to setup the trigger (which is any SMS received)</li>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0tu_mJA2w8I1DHRMr4OEjnOVvm_liKYXtfEQDfwsbqeQ-_udcVTt4-PE8VgY7kLkBKxKJxwoY-UPJ7S1AodfQk5-V8RIElwCZDcvvAHu-sEjcbhCtv-FYWcPgZ2eOjlHsjlN4wzElAfU/s1600/IFTTT-AppletMaker.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="152" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0tu_mJA2w8I1DHRMr4OEjnOVvm_liKYXtfEQDfwsbqeQ-_udcVTt4-PE8VgY7kLkBKxKJxwoY-UPJ7S1AodfQk5-V8RIElwCZDcvvAHu-sEjcbhCtv-FYWcPgZ2eOjlHsjlN4wzElAfU/s320/IFTTT-AppletMaker.JPG" width="320" /></a></div>
<li>Start typing "android" and then click on "Android SMS"</li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEv41jLZMKeGcCK04tsSJVVsaaEAR8xR87J1iTYK5oi6oUySM6Sw9R9MuCLOwfgCXU6qHtJpay4G3HStk11iiZAFS2HunsePFKIW9kGb-9w7CsrdbMrPOp3tq7nYfI9XjIjiOuwdhaL-E/s1600/IFTTT-ChooseServiceJPG.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="176" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEv41jLZMKeGcCK04tsSJVVsaaEAR8xR87J1iTYK5oi6oUySM6Sw9R9MuCLOwfgCXU6qHtJpay4G3HStk11iiZAFS2HunsePFKIW9kGb-9w7CsrdbMrPOp3tq7nYfI9XjIjiOuwdhaL-E/s400/IFTTT-ChooseServiceJPG.JPG" width="400" /></a></div>
<li>Now click on "Any new SMS received"</li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu2b7qo5h1rgaD-7SL6NI9pQ5LuFCICuZGI07piBh5mQwy2VXcMRrIMyc-rtpdYBpK4fWdLOyGzJLCq_fi85WKQN00232VmRzdbwJBDrdSGPvmamAjStixjFBkAxg6_1-uZKetr91zhyphenhyphenE/s1600/IFTTT-ChooseTrigger.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu2b7qo5h1rgaD-7SL6NI9pQ5LuFCICuZGI07piBh5mQwy2VXcMRrIMyc-rtpdYBpK4fWdLOyGzJLCq_fi85WKQN00232VmRzdbwJBDrdSGPvmamAjStixjFBkAxg6_1-uZKetr91zhyphenhyphenE/s400/IFTTT-ChooseTrigger.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<li>Now click on "+that" to setup the Action</li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgljs115obiqtia0_FNk1PZjYS54ZP8S10Rbn6yXZiOt_PJAMFBs1LXuhpSb1_9r9P_tFojWJj_R3AD2xXONMDSq5KfZR-bRi7ROhCZD6nto0kvxAmPebMHD1fMzAVRjTaGtKkKfxZFspA/s1600/IFTTT-Action.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="74" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgljs115obiqtia0_FNk1PZjYS54ZP8S10Rbn6yXZiOt_PJAMFBs1LXuhpSb1_9r9P_tFojWJj_R3AD2xXONMDSq5KfZR-bRi7ROhCZD6nto0kvxAmPebMHD1fMzAVRjTaGtKkKfxZFspA/s320/IFTTT-Action.JPG" width="320" /></a></div>
<li>Start typing "maker" and select the "Maker" action service. </li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1VVtjmKo4DezrJDVS1k_S4xU8WqvsyMStC9may_WLIKNrC8vaCO2D8iAdJFj3JfbjdaBVe8F6-pGxVfJZd0adXhfhGQRka4avU-ttD4285Nr-GJmlXTtUS8ESrlrizdeMO475iSMXJJI/s1600/IFTTT-ChooseActionService.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="229" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1VVtjmKo4DezrJDVS1k_S4xU8WqvsyMStC9may_WLIKNrC8vaCO2D8iAdJFj3JfbjdaBVe8F6-pGxVfJZd0adXhfhGQRka4avU-ttD4285Nr-GJmlXTtUS8ESrlrizdeMO475iSMXJJI/s320/IFTTT-ChooseActionService.JPG" width="320" /></a></div>
<li>Click on "Make a web request"</li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRC-yPAaAM9AGL7Fcr4S2a-JDy0RjlkUSVzLg4m_WUDBw-IYo1yQR1UsxWRewCU-YKukugmJQ_PZS6euGjH6fbBmlTNcVBWrIno-3SFoBxrX9tUYovxxgSLSzqdO4ZffZ4D8V1AiDehAk/s1600/IFTTT-ChooseActionMaker.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRC-yPAaAM9AGL7Fcr4S2a-JDy0RjlkUSVzLg4m_WUDBw-IYo1yQR1UsxWRewCU-YKukugmJQ_PZS6euGjH6fbBmlTNcVBWrIno-3SFoBxrX9tUYovxxgSLSzqdO4ZffZ4D8V1AiDehAk/s320/IFTTT-ChooseActionMaker.jpg" width="320" /></a></div>
<li>Fill in the web request as below:</li>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT585uFgFoVhx_HmThthXCBEBQJFWyo9lTL8ZLbHjtfhRFSZxa94vfMPwWLOHFDs0_flKugzkRplAEXW2q2jiLdqOhKbj35c0nCat0JzwQLbB7ragVBPkKwaNVJbry8oWHmQzCH25nye4/s1600/IFTTT-MakerWebRequest.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT585uFgFoVhx_HmThthXCBEBQJFWyo9lTL8ZLbHjtfhRFSZxa94vfMPwWLOHFDs0_flKugzkRplAEXW2q2jiLdqOhKbj35c0nCat0JzwQLbB7ragVBPkKwaNVJbry8oWHmQzCH25nye4/s640/IFTTT-MakerWebRequest.jpg" width="289" /></a></div>
<ul>
<li>Change the URL to the address of your webserver. </li>
<li>The JSON Body Text is below which is easier to copy and paste. This sends the info about your SMS message to your php page using JSON</li>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">{<span style="color: #007700;">"contact"</span>:<span style="background-color: #fff0f0;">"{{ContactName}}"</span> , <span style="color: #007700;">"message"</span>:<span style="background-color: #fff0f0;">"{{Text}}"</span> , <span style="color: #007700;">"Occured"</span>:<span style="background-color: #fff0f0;">"{{OccurredAt}}"</span>, <span style="color: #007700;">"FromNumber"</span>:<span style="background-color: #fff0f0;">"{{FromNumber}}"</span>}
</pre>
</div>
</ul>
<div>
<br /></div>
<li>Hit Save and you're done </li>
<li>You can rename the Applet to whatever you want, and can toggle whether you want logging</li>
</ul>
<div>
<br /></div>
</div>
<div>
<b><u>5.Test it out</u></b></div>
<div>
<b><br /></b></div>
<div>
Now all you need to do is test it out. Get somebody to send you a text or send one to yourself and hopefully you should hear your Raspberry PI (remember to turn on the speakers and volume is up) say "SMS received from" and then the name from your address book</div>
<div>
<br /></div>
<div>
<b><u>6.Customise it</u></b></div>
<div>
<br /></div>
<div>
Now you can tailor this to do whatever you want. Maybe read out the full message, or use one for the other triggers. Or maybe get your php page to perform some other action like turning on lights</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Hope the above is helpul. Any problems , please leave something in the comments.</div>
<div>
<b><br /></b></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc18"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc18"><br /></span></div>
<div>
<br /></div>
<style type="text/css">
span {
font-family: 'Courier New';
font-size: 10pt;
color: #000000;
}
.sc18 {
color: #FF0000;
background: #FDF8E3;
}
.sc118 {
background: #FEFCF5;
}
.sc119 {
color: #808080;
background: #FEFCF5;
}
.sc120 {
color: #808080;
background: #FEFCF5;
}
.sc121 {
font-weight: bold;
color: #0000FF;
background: #FEFCF5;
}
.sc123 {
color: #000080;
background: #FEFCF5;
}
.sc125 {
color: #008000;
background: #FEFCF5;
}
.sc127 {
color: #8000FF;
background: #FEFCF5;
}
</style></div>
SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com14tag:blogger.com,1999:blog-5599902997355913399.post-29510200531231712522017-01-11T19:22:00.000+00:002017-02-06T17:14:02.946+00:00Building an Amazon Echo Like Device with a Raspberry Pi and Google Cloud Speech Api<div dir="ltr" style="text-align: left;" trbidi="on">
In <a href="http://randomconsultant.blogspot.com/2016/12/get-your-raspberry-pi-to-speak-news.html">my previous post</a> I showed how I wrote a python script to read out the latest news headlines using Googles text to speech api. As I commented in that post, voice recognition and talking devices seem to be the in thing with the release of the <a href="http://www.amazon.co.uk/echo">Amazon Echo</a> and <a href="https://madeby.google.com/home">Google Home</a>.<br />
<br />
In this post I show how I created a python script to record sound on your raspberry pi, invoke the google cloud speech api to interpret what was said, and then perform a command on your raspberry pi - so a bit like a basic <a href="http://www.amazon.co.uk/echo">Amazon Echo</a>.<br />
<br />
<b><u>Setting up your mic</u></b><br />
<br />
Before I get into the python code, you need a mic setup. As the Raspberry Pi does not have a soundcard you will need a USB mic or a webcam which has an inbuilt mic. I went for the latter and used a basic <a href="https://www.amazon.co.uk/Logitech-C270-HD-Webcam-Black/dp/B003R1O320">webcam from logitech</a>.<br />
<br />
Once you have your mic plugged in, follow the instructions in the "Step 1: Checking Your Microphone" in:<a href="https://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/"> https://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/</a><br />
<br />
<b><u>Install prerequisites</u></b><br />
<br />
There is one python library you need which is <a href="http://pycurl.io/docs/latest/install.html">pycURL</a>, which is used to send data to the Google Cloud Speech Api. Follow the instructions here: <a href="http://pycurl.io/docs/latest/install.html">http://pycurl.io/docs/latest/install.html</a><br />
<br />
You will also need to install <a href="http://sox.sourceforge.net/">SoX </a>which is an opensource tool to analyse sound files. This is used in the script to detect whether any sound is on the recorded audio, before trying to send it to the google api.<br />
<br />
You can install this by running:<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, courier; font-size: 14px; line-height: 1.3em; padding: 1em;"> sudo apt-get install sox</pre>
<div>
<br />
One more thing to install, flac . Flac is used to record your sound file in a lossless format which is required by the google api:<br />
<br />
You can install this by running:<br />
<br />
<br />
<div>
</div>
<br />
<pre style="-webkit-text-stroke-width: 0px; background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); color: black; font-family: monospace, courier; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal; letter-spacing: normal; line-height: 1.3em; margin: 0px; orphans: 2; padding: 1em; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px;"> sudo apt-get install flac</pre>
<br /></div>
<div>
<b><u>Setup Google Cloud Speech Api</u></b></div>
<div>
<br /></div>
<div>
To do the voice to text processing I am using the speech api which is part of Google Cloud. It is in beta at the moment and offering a free trial.</div>
<div>
<br /></div>
<div>
Follow the instructions on the their site to get your api key which will be needed in the script:</div>
<div>
<a href="https://cloud.google.com/speech/">https://cloud.google.com/speech/</a></div>
<div>
<br /></div>
<div>
The current downside I've found with this api is the latency. It's currently taking 5-6 seconds for a response to process a 2 second audio file. The google help files yes the response time should be similar to the length of audio being processed. </div>
<div>
<br /></div>
<div>
<b><u>Python Script</u></b></div>
<div>
<br /></div>
<div>
Now to the actual python code. </div>
<div>
<br /></div>
<div>
All the files required can be downloaded from here:</div>
<div>
<a href="https://www.dropbox.com/sh/r0e787digng1rgv/AADMGKH6dBTVpPi2yMLtIcYxa/Rpi%20Speech?dl=0">https://www.dropbox.com/sh/r0e787digng1rgv/AADMGKH6dBTVpPi2yMLtIcYxa/Rpi%20Speech?dl=0</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
The main file to look at is <b><i>speechAnalyser.py</i></b>.</div>
<div>
<br /></div>
<div>
This script does the following:</div>
<div>
<br /></div>
<div>
1. If no audio is playing (you don't want to record if you're playing something on your speakers), records sound from your microphone for 2 seconds</div>
<div>
2. Uses SoX to check if any sound is on the file and is above a certain amplitude - this helps to not bother processing when there is silence or just background noises</div>
<div>
3. If there is sound at a sufficient amplitude, then send the audio to the google api with a JSON message. As said earlier the google api takes a 5-6 seconds and returns a JSON message with the words detected.</div>
<div>
4. If the trigger word in this case "Jarvis" is said during these two seconds, a beep sound is played.</div>
<div>
5 Records another 3 seconds to listen for a user speaking a commandand sends to the google api like step 3</div>
<div>
6.Checks if keyword found in returned text and executes the appropriate command. For example if "news" is mentioned it invokes the GetNews script which I described in <a href="http://randomconsultant.blogspot.co.uk/2016/12/get-your-raspberry-pi-to-speak-news.html">my previous post</a>.<br />
7. Loops back to Step 1. </div>
<div>
<br /></div>
<div>
Remeber to change the line below where it says <add key="" your=""> with the key which was provided when you set up the <a href="https://cloud.google.com/speech/">Google Cloud Speech api</a></add></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, courier; font-size: 14px; line-height: 1.3em; padding: 1em;">key = '<add key="" your="">'
stt_url = 'https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=' + ke</add></pre>
</div>
<div>
<br /></div>
<div>
Also you should customise your commands in the following section of code:</div>
<div>
<br /></div>
<div>
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, courier; font-size: 14px; line-height: 1.3em; padding: 1em;">def listenForCommand():
command = transcribe(3)
print time.strftime("%Y-%m-%d %H:%M:%S ") + "Command: " + command
success=True
if command.lower().find("light")>-1 and command.lower().find("on")>-1 :
subprocess.call(["/usr/local/bin/tdtool", "-n 1"])
elif command.lower().find("light")>-1 and command.lower().find("off")>-1 :
subprocess.call(["/usr/local/bin/tdtool", "-f 1"])
elif command.lower().find("news")>-1 :
os.system('python getNews.py')
elif command.lower().find("weather")>-1 :
os.system('python getWeather.py')
elif command.lower().find("pray")>-1 :
os.system('python sayPrayerTimers.py')
elif command.lower().find("time")>-1 :
subprocess.call(["/home/pi/Documents/speech.sh", time.strftime("%H:%M") ])
elif command.lower().find("tube")>-1 :
os.system('python getTubeStatus.py')
else:
subprocess.call(["aplay", "i-dont-understand.wav"])
success=False
return success </pre>
</div>
<div>
<br />
The other interesting part of the script to look at is, where it sends the data over to the Google Cloud Speech Api.<br />
<br />
It creates a JSON message, and then encodes the audio in base64.<br />
<br />
Within the outgoing JSON message, there is a phrases section, where I've included my trigger word "Jarvis", which makes it more likely the speech engine recognises this<br />
<br />
The final bit then gets the text from the response.<br />
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: "andale mono", "lucida console", monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 653px;"><code>#Send sound to Google Cloud Speech Api to interpret
#----------------------------------------------------
print time.strftime("%Y-%m-%d %H:%M:%S ") + "Sending to google api"
# send the file to google speech api
c = pycurl.Curl()
c.setopt(pycurl.VERBOSE, 0)
c.setopt(pycurl.URL, stt_url)
fout = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, fout.write)
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
with open(filename, 'rb') as speech:
# Base64 encode the binary audio file for inclusion in the JSON
# request.
speech_content = base64.b64encode(speech.read())
jsonContentTemplate = """{
'config': {
'encoding':'FLAC',
'sampleRate': 16000,
'languageCode': 'en-GB',
'speechContext': {
'phrases': [
'jarvis'
],
},
},
'audio': {
'content':'XXX'
}
}"""
jsonContent = jsonContentTemplate.replace("XXX",speech_content)
#print jsonContent
start = time.time()
c.setopt(pycurl.POSTFIELDS, jsonContent)
c.perform()
#Extract text from returned message from Google
#----------------------------------------------
response_data = fout.getvalue()
end = time.time()
#print "Time to run:"
#print(end - start)
#print response_data
c.close()
start_loc = response_data.find("transcript")
temp_str = response_data[start_loc + 14:]
#print "temp_str: " + temp_str
end_loc = temp_str.find("\""+",")
final_result = temp_str[:end_loc]
#print "final_result: " + final_result
return final_result
</code></pre>
<br />
<br /></div>
<div>
<br /></div>
<div>
I have to give a big shout out to the following sites which gave me ideas on how to write this script:</div>
<div>
<br /></div>
<div>
<a href="https://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/">https://diyhacking.com/best-voice-recognition-software-for-raspberry-pi/</a> - This contains the instructions on how to setup a microphoen on the raspberry pi</div>
<div>
<a href="https://github.com/StevenHickson/PiAUISuite">https://github.com/StevenHickson/PiAUISuite</a> - Full Application which does what the above script does but is configurable. But not sure if it still works with the new Google Speech Api</div>
<div>
<br /></div>
</div>
SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com24tag:blogger.com,1999:blog-5599902997355913399.post-39006946422128503092016-12-15T17:00:00.000+00:002017-01-17T16:15:06.021+00:00Get your Raspberry Pi to Speak the News<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Talking devices are the in thing at the moment with the <a href="http://www.amazon.co.uk/echo">Amazon Echo</a> and the newer <a href="https://madeby.google.com/home/">Google Home</a>, so I thought I would try to get my raspberry pi to read out the news.<br />
<br />
Here's what you need to do:<br />
<br />
1, Install mplayer (audio player) on your raspberry pi<br />
2. Setup a script to invoke Google Translates text to speech engine<br />
3. Create a Python Script to pull the latest headlines from the BBC rss feed and then read them out<br />
4. Add the script as a cron job to run every hour<br />
<br />
Below is the detail behind each step<br />
<br />
<b><u>1. Install mplayer on your raspberry pi</u></b><br />
<b><u><br /></u></b>
(The below instructions are based on <a href="http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)">http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)</a>)<br />
<b><u><br /></u></b>
a. First you will need to update Raspian (this can take up to an hour if not run in some time)<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">sudo apt-get update
sudo apt-get upgrade</pre>
<br />
b. Add sound utilities<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;"> sudo apt-get install alsa-utils</pre>
<br />
c. Edit the follow file with the line<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">sudo nano /etc/modules</pre>
<br />
to have line<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;"> snd_bcm2835 </pre>
<br />
d. Install mplayer<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">sudo apt-get install mplayer</pre>
<br />
<b><u>2. Setup a script to invoke Google Translates text to speech engine</u></b><br />
<br />
a. Create a file call <b>speech.sh</b> with the following content:<br />
<br />
<br />
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: "Times New Roman"; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<br />
<pre style="-webkit-text-stroke-width: 0px; border: 1px dashed rgb(153, 153, 153); color: black; font-family: "andale mono", "lucida console", monaco, fixed, monospace; font-size: 12px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; margin: 0px; orphans: 2; overflow: auto; padding: 5px; text-align: left; text-indent: 0px; text-transform: none; widows: 2; width: 653px; word-spacing: 0px;"><code><span style="background-color: #eeeeee;"><pre><code>#!/bin/bash
say() { local IFS=+;/usr/bin/mplayer -volume 100 -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=$*&tl=En-us"; }
say $*</code></pre>
</span></code></pre>
<br />
<br />
b. Add execute permissions to the script<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">chmod u+x speech.sh</pre>
<br />
c. Test it out<br />
<style type="text/css">
span {
font-family: 'Courier New';
font-size: 10pt;
color: #000000;
}
.sc0 {
}
.sc2 {
color: #008000;
}
.sc3 {
color: #FF0000;
}
.sc4 {
font-weight: bold;
color: #0000FF;
}
.sc5 {
color: #808080;
}
.sc7 {
font-weight: bold;
color: #804000;
}
.sc8 {
}
.sc9 {
font-weight: bold;
color: #FF8040;
background: #FFFFD9;
}
.sc69 {
text-decoration: underline;
color: #808080;
}
</style>
<br />
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: #FFFFFF; float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">./speech.sh Hello I can talk</pre>
<br />
<b>Remember </b>you will need speakers plugged into your raspberrypi to hear anything!<br />
<br />
<b><u>3. Create a Python Script to pull the latest headlines from the BBC rss feed and then read them out</u></b><br />
<br />
a, Install feedparser which is a python libararyto read <a href="https://en.wikipedia.org/wiki/RSS">RSS </a>feeds. Follow the instructions from the below link:<br />
<br />
<a href="https://pypi.python.org/pypi/feedparser#downloads">https://pypi.python.org/pypi/feedparser#downloads</a><br />
<br />
b. Create a file <b>getNews.py</b> with the following content<br />
<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); line-height: 1.3em; padding: 1em;"><span style="font-family: monospace , "courier";"><span style="font-size: 14px;">##!/usr/bin/env python
import subprocess
import feedparser
import time
d = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml?edition=uk')
introMessage = "BBC News Headlines at " + time.strftime("%H:%M")
subprocess.call(["/home/pi/Documents/speech.sh", introMessage])
maxItems = 3
itemCounter = 0
for post in d.entries:
print post.title
subprocess.call(["/home/pi/Documents/speech.sh", post.title])
itemCounter = itemCounter + 1
if itemCounter == maxItems:
break</span></span><span style="font-family: monospace , "courier"; font-size: 14px;">
</span></pre>
<div>
<br /></div>
<div>
Remember to change the location to where you saved speech.sh</div>
<div>
Also change <b>maxItems </b>if you want the script to read out more than 3 headlines. </div>
<div>
You could change the link to another news website of your choice as long as they provide a rss feed.</div>
<div>
<br /></div>
c. Test the file<br />
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">python getNews.py</pre>
<div>
<br /></div>
<div>
You should hear the top 3 headlines read out</div>
<br />
<span style="font-family: "times new roman"; font-size: small;"><b><u>4. Add the script as a cron job to run every hour</u></b> </span><span style="font-family: "times new roman"; font-size: small;">(or how every frequently you want)</span><br />
<br />
a. Open crontab with:<br />
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">crontab -e</pre>
<br />
b. Add the line<br />
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<div style="background: rgb(255, 255, 255); float: left; line-height: 1; white-space: pre;">
<span class="sc9"><br /></span></div>
<br />
<pre style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); font-family: monospace, Courier; font-size: 14px; line-height: 1.3em; padding: 1em;">@hourly python /home/pi/Documents/getNews.py > /dev/null 2>&1</pre>
<div>
<br /></div>
<div>
<br /></div>
Check out the following site on how to set up cron jobs if not familiar:<br />
<a href="http://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files">http://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files</a>/<br />
<br />
<br />
And there you go, you now have a news reading speaking rasperberry pi. You could adapt this to read out any other type of site which uses <a href="https://en.wikipedia.org/wiki/RSS">rss </a>feeds.<br />
<br />
The following files can be downloaded from the links below:<br />
<br />
<a href="https://www.dropbox.com/s/isxptfky51cppd5/getNews.py?dl=0">getNews.py</a><br />
<a href="https://www.dropbox.com/s/d4ps0rveoo1p8an/speech.sh?dl=0">speech.sh</a><br />
<br />
<br /></div>
SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com1tag:blogger.com,1999:blog-5599902997355913399.post-22506249220481207382013-07-24T12:47:00.000+01:002017-01-17T16:15:19.734+00:00Turn your Raspberry Pi into an Azaan/Prayer clock<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Recently I've been playing with the <a href="http://www.raspberrypi.org/faqs">raspberry pi</a> and given it's <a href="https://en.wikipedia.org/wiki/Ramadan">Ramadan</a>, I thought I'd see if I could turn it into an <a href="http://en.wikipedia.org/wiki/Adhan">Azaan </a>(Islamic call to prayer) clock. Given the RPI is low powered I can leave it on and it doesn't need a monitor, keyboard, mouse, etc plugged in.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">This is what I did:</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">1. Plug in a speaker into the 3.5mm audio output on the raspberry pi</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">2. Download python code from <a href="http://praytimes.org/code/">prayTimes.org</a> to calculate prayer times</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">3. Download azaan mp3 from <a href="http://praytimes.org/audio/">prayTimes.org</a> again.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">4. Write a python script to set jobs in crontab to play the azaan mp3 at the appropriate time (see code below or <a href="https://dl.dropboxusercontent.com/u/427946/RPi%20Azaan%20Clock/updateAzaanTimers.py">download here</a>). The python code from prayTimes.org has to be in the same folder for this to work.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">My script </span>utilizes the python crontab library. More info on setting this up available on the links below<br />
<br />
Python crontab: <a href="http://pypi.python.org/pypi/python-crontab/">http://pypi.python.org/pypi/python-crontab/</a><br />
Installing modules: <a href="http://docs.python.org/2/install/index.html">http://docs.python.org/2/install/index.html</a><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">The bits you may need to configure yourself are:</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">a) Longitude and Latitude (currently set to London UK)</span><br />
<pre style="border: 1px dashed rgb(153, 153, 153); font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 653px;"><code><span style="background-color: #eeeeee;">lat = </span><span style="background-color: yellow;">51.5171</span><span style="background-color: #eeeeee;">
long = </span><span style="background-color: yellow;">0.1062</span></code></pre>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">b) Timezone (currently set to 0+GMT and daylight savings =1 )</span><br />
<pre style="border: 1px dashed rgb(153, 153, 153); font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 653px;"><code><span style="background-color: #eeeeee;">times = PT.getTimes((now.year,now.month,now.day), (lat, long), </span><b style="background-color: yellow;">0</b><span style="background-color: #eeeeee;">,</span><span style="background-color: yellow;">1</span><span style="background-color: #eeeeee;">) </span></code></pre>
<br />
c) Location of azaan mp3:<br />
<pre style="border: 1px dashed rgb(153, 153, 153); font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 653px;"><code><span style="background-color: #eeeeee;">strPlayAzaanMP3Command = 'omxplayer -o local </span><b style="background-color: yellow;">/home/pi/Downloads/Abdul-Basit.mp3</b><span style="background-color: #eeeeee;"> > /dev/null 2>&1'
</span></code></pre>
<div>
<code><br /></code></div>
<span style="font-family: inherit;">The code from <a href="http://praytimes.org/wiki/Code_Manual">prayTimes.org</a> is really configurable, so you can change the prayer time calculation method and a whole load of other adjustments. </span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">5. Add a job in <a href="http://www.unixgeeks.org/security/newbie/unix/cron-1.html">crontab </a>to run this script on a daily basis to update the azaan times:</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"># m h dom mon dow command</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">0 1 * * * python /home/pi/Documents/updateAzaanTimers.py > /dev/null 2>&1</span><br />
<br />
6. You're done. For each prayer , the raspberry pi will play the azaan mp3 via the speaker.<br />
<br />
For All code and audio files I've used/written are available on the link below:<br />
<a href="https://www.dropbox.com/sh/r0e787digng1rgv/OmCXiu9Vx_/RPi%20Azaan%20Clock">https://www.dropbox.com/sh/r0e787digng1rgv/OmCXiu9Vx_/RPi%20Azaan%20Clock</a><br />
<br />
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>#!/usr/bin/env python
import datetime
from praytimes import PrayTimes
#Get Prayer Times
#--------------------
lat = 51.5171
long = 0.1062
now = datetime.datetime.now()
PT = PrayTimes('ISNA')
times = PT.getTimes((now.year,now.month,now.day), (lat, long), 0,1)
print times['fajr']
print times['dhuhr']
print times['asr']
print times['maghrib']
print times['isha']
#Update Crontab with Prayer Times
#---------------------------------
from crontab import CronTab
#Function to add azaan time to cron
def addAzaanTime (strPrayerName, strPrayerTime, objCronTab, strCommand):
job = objCronTab.new(command=strCommand,comment=strPrayerName)
timeArr = strPrayerTime.split(':')
hour = timeArr[0]
min = timeArr[1]
job.minute.on(int(min))
job.hour.on(int(hour))
print job
return
system_cron = CronTab()
strPlayAzaanMP3Command = 'omxplayer -o local /home/pi/Downloads/Abdul-Basit.mp3 > /dev/null 2>&1'
jobs = system_cron.find_command(strPlayAzaanMP3Command)
print jobs
for j in jobs:
system_cron.remove(j)
addAzaanTime('fajr',times['fajr'],system_cron,strPlayAzaanMP3Command)
addAzaanTime('dhuhr',times['dhuhr'],system_cron,strPlayAzaanMP3Command)
addAzaanTime('asr',times['asr'],system_cron,strPlayAzaanMP3Command)
addAzaanTime('maghrib',times['maghrib'],system_cron,strPlayAzaanMP3Command)
addAzaanTime('isha',times['isha'],system_cron,strPlayAzaanMP3Command)
system_cron.write()
</code></pre>
</div>
SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com22tag:blogger.com,1999:blog-5599902997355913399.post-25772812718641000292010-11-04T16:11:00.000+00:002010-11-04T16:11:19.265+00:00Fix when Android Market cannot download<div class="separator" style="clear: both; text-align: center;"><a href="http://www.ubergizmo.com/photos/2009/4/no_android_market.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://www.ubergizmo.com/photos/2009/4/no_android_market.jpg" /></a></div><br />
On my <a href="http://www.htc.com/www/product/g1/overview.html">G1</a> running <a href="http://developer.android.com/sdk/android-1.6-highlights.html">Android 1.6</a>, I started to have problems with the Android Market. Any application that I tried to update or install resulted in an error message saying that the download was unsuccessful.<br />
<br />
Luckily with a bit of <a href="http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=android+market+downloads+not+successful">googling</a>, this is what I did to resolve the problem<br />
<br />
1. Open <b>Settings</b><br />
2. Select <b>Applications</b><br />
3. Select <b>Manage Applications</b><br />
4. Select <b>Market </b>and the select <b>Clear Cache</b><br />
5. Repeat step 4 and clear the cache for <b>Google Apps</b>, <b>Google Talk</b> and <b>Checkin Service</b>.<br />
6. Restart your phone<br />
<br />
When you open the market it will ask you to login to your google account with your username and password. Once logged in , you will be able to download and update apps. <br />
<br />
These instructions are based on:<br />
<a href="http://www.technipages.com/android-market-download-unsuccessful-error-fix.html">http://www.technipages.com/android-market-download-unsuccessful-error-fix.html</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-84980577383884882542010-08-05T11:58:00.003+01:002010-08-05T12:01:39.613+01:00Install Flash in Google Chrome Portable without Admin RightsIf you need to install Chrome and you don't have admin rights on your windows machine, then the best thing to do is to use a portable version, available from <a href="http://portableapps.com/">portableapps.com</a> :<br />
<br />
<a href="http://portableapps.com/apps/internet/google_chrome_portable">http://portableapps.com/apps/internet/google_chrome_portable</a><br />
<br />
You can put this anywhere on your machine or even on a usb stick.<br />
<br />
However if you want to use sites like youtube or google streetview, you will need Adobe Flash Player. As you don't have admin rights you will not be able to run the standard abobe installer.<br />
<br />
This is what you need to do instead:<br />
<br />
1. Download this file from Adobe: <a href="http://fpdownload.macromedia.com/get/flashplayer/xpi/current/flashplayer-win.xpi">http://fpdownload.macromedia.com/get/flashplayer/xpi/current/flashplayer-win.xpi</a><br />
<br />
2. Rename the file extenion from .xpi to .zip <br />
<br />
3. Use an unzip program like winzip or <a href="http://www.7-zip.org/">7-zip</a> to extract the contents<br />
<br />
4. Copy the files flashplayer.xpt and NPSWF32.dll from the contents of the zip to the folder \App\Chrome-Bin\5.0.375.55\Plugins <br />
<br />
This will be where you installed Google Chrome and the 5.0.365.55 folder might be named differently.<br />
<br />
5. Restart Chrome and enter this in the address bar: about:plugins . You should see Shockwave Flash listed as a plugin.<br />
<br />
6. Try out <a href="http://www.youtube.com">youtube.com</a><br />
<br />
These instructions are kind of based on:<br />
<a href="http://eurekatips.com/2009/05/05/flash-google-chrome-manual-permission-portable/724/">http://eurekatips.com/2009/05/05/flash-google-chrome-manual-permission-portable/724/</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-85000444285559696282010-07-23T13:18:00.000+01:002010-07-23T13:18:15.946+01:00Run a command and read console output in VB6 / VBANeeded to run a command line program from code and read the input. Found this useful code to do it:<br />
<br />
<script src="http://friendpaste.com/3aNELWiC1ed4bzApDhYIPl.js"></script>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-2453344037970855372010-06-30T15:56:00.003+01:002010-06-30T16:04:35.444+01:00Official Skype Install for Acer Aspire 1 (aa1)Just got Skype running on my aa1 running Linpus Linux. There are a few blog posts out there with instructions, but I found an official download from Acer which is a lot more straight forward and worked for me where other methods didn't.<br /><br />Just follow the instructions at: <a href="http://www.acer.com/aspireone/support/files/connect.html#002">http://www.acer.com/aspireone/support/files/connect.html#002</a><br /><br />There are also instructions too on how to install support for 3G USB sticks (Huawei 3G dongles) which I haven't tried out , buy let me know if it works for you: <a href="http://www.acer.com/aspireone/support/files/connect.html#003">http://www.acer.com/aspireone/support/files/connect.html#003</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-65747540026794234702010-05-08T17:51:00.002+01:002010-05-08T17:55:00.837+01:00Half of LCD Monitor is YellowI have a 19" LCD Monitor from LG . A little while ago the right half of the screen had a yellow tint to it. I played around with the cables for ages but it was no use.<br /><br />I considered buying a new monitor cable or even returning the monitor for repair until I tried out one thing. I went into the M<strong>onitor menu, went into settings and selected Factory Reset.... once I selected this, after a few seconds the screen was back to normal</strong>... yipeee ... hope this helps somebody else out.SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-82635000508252676582009-08-11T09:51:00.003+01:002009-08-11T10:18:06.799+01:00Visual Studio TricksI am going to keep this as an ongoing post with whatever tips and tricks I come across when using Visual Studio.<div><br /></div><div><b><span class="Apple-style-span" style="font-size: large;">Show Active File In Solution Explorer</span></b></div><div><br /></div><div>When working with big solutions and projects this is so useful. By default visual studio doesn't highlight the file that is active (i.e the one you are viewing) in Solution Explorer. </div><div><br /></div><div>To activate this do the following:</div><div></div><span><span><br />Tools – Options – Projects and Solutions – Track Active Item in Solution Explorer</span></span><div><span class="Apple-style-span" style=" font-weight: bold; line-height: 19px; font-size:11px;"><span class="Apple-style-span" style="font-family:arial;"></span></span></div><div><span class="Apple-style-span" style="font-family:'Lucida Grande';font-size:100%;color:#7F7F7F;"><span class="Apple-style-span" style=" line-height: 19px;font-size:11px;"><b><br /></b></span></span></div><div>Credit for this tip goes to <a href="http://www.ronaldwidha.net/2008/11/26/visual-studio-show-active-file-in-solution-explorer/">Ronald Widha's blog </a>.</div><div><br /></div><div><b><span class="Apple-style-span" style="font-size: large;">Use the Command Window to Search for Files</span></b></div><div><b><br /></b></div><div>In Visual Studio I really miss the equivalent of Eclipse's CTRL - T shortcut to search for classes. </div><div><br /></div><div>The next best thing I have found is to open the command window ( View > Other Windows > Command Window ) and type:</div><div><br /></div><div>>open <i>file you're searching for </i></div><div><i><br /></i></div><div>and a little drop down will pop up of files that start with whatever you have typed in.</div><div><br /></div><div><b><span class="Apple-style-span" style="font-size: large;">More Tricks</span></b></div><div><br /></div><div>Also check out any of my blog entries tagged with <a href="http://randomconsultant.blogspot.com/search/label/visual%20studio">visual studio</a></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><br /></div><div><span class="Apple-style-span" style="font-family:'Lucida Grande';font-size:100%;color:#7F7F7F;"><span class="Apple-style-span" style=" line-height: 19px;font-size:11px;"><b><br /></b></span></span></div><div><span class="Apple-style-span" style="font-family:'Lucida Grande';font-size:100%;color:#7F7F7F;"><span class="Apple-style-span" style=" line-height: 19px;font-size:11px;"><b><br /></b></span></span></div>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-19326322206554172242009-08-10T13:30:00.005+01:002009-08-10T14:06:36.488+01:00Installing flash for firefox in xubuntuThis weekend I was trying to get the flash player installed on XUbuntu and working on firefox. Following the instructions on Adobe's site didn't work , but after a bit of googling this is what I did and it worked.<div><br /></div><div>1. Download Adobe Flash Player from <a href="http://get.adobe.com/flashplayer/otherversions/">http://get.adobe.com/flashplayer/otherversions/</a>. Choose the tar.gz option.</div><div><br /></div><div>2. Extract the contents of the extracted file to your desktop . The file <b>libflashplayer.so</b> should now be on your desktop</div><div><br /></div><div>3. Open up a terminal window</div><div><br /></div><div>4. Enter the following , and replace <b>username </b>with your username.</div><div><br /></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>sudu su<br /></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>cd <span class="Apple-style-span" style="white-space: pre; "><span class="Apple-style-span" style="font-size:medium;">/usr/lib/mozilla/plugins/</span></span></div><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-tab-span" style="white-space:pre"> </span>cp /home/<b>username</b><username>/desktop/libflashplayer.so .<br /></username></span></div><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-tab-span" style="white-space:pre"> </span>cd /usr/lib/firefox/plugins/<br /></span></div><div><span class="Apple-style-span" style="white-space: pre;"><span class="Apple-tab-span" style="white-space:pre"> </span>cp /home/<b>username</b><username>/desktop/libflashplayer.so .</username></span></div><div><span class="Apple-style-span" style="white-space: pre;"><br /></span></div><div><span class="Apple-style-span" style="white-space: pre;">5. Restart firefox (maybe a couple of times)</span></div><div><span class="Apple-style-span" style="white-space: pre;"><br /></span></div><div><span class="Apple-style-span" style="white-space: pre;">6. Test out <a href="http://www.youtube.com/">youtube.com</a></span></div><div><span class="Apple-style-span" style="font-size:100%;"><span class="Apple-style-span" style=" white-space: pre;font-size:13px;"><span class="Apple-tab-span" style="white-space:pre"> </span><br /></span></span></div><div><br /></div>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-88027846493588567032009-03-10T08:58:00.004+00:002009-03-10T09:09:04.088+00:00Show delicious saves and tags on blog<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAS_5Z3DWpG5vkeN1gUxgXs5h845nllw5NTXof39kq8RsW1wvZrCk_Cv2LmYRBu8DoXIU-GnaXyf8kviMXMFMkRAfeQEk5BBT6vYgsT6urOpW598H9X2fQPSa5HChDT3MQu9rOxrV8m8c/s1600-h/delicioustagometer.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 41px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAS_5Z3DWpG5vkeN1gUxgXs5h845nllw5NTXof39kq8RsW1wvZrCk_Cv2LmYRBu8DoXIU-GnaXyf8kviMXMFMkRAfeQEk5BBT6vYgsT6urOpW598H9X2fQPSa5HChDT3MQu9rOxrV8m8c/s320/delicioustagometer.jpg" alt="" id="BLOGGER_PHOTO_ID_5311481686664171154" border="0" /></a><br />This is a useful feature from <a href="http://delicious.com/">delicious </a>where you can show how many people have saved your page as a bookmark on <a href="http://delicious.com">delicious </a>and the tags people have used.<br /><br />You can probably see this at the bottom of this page.<br /><br />Just go to <a href="http://delicious.com/help/tagometer">http://delicious.com/help/tagometer</a> and it has a snippet of javascript to copy and paste into your page.<br /><br />To add a snippet of html/javascript to blogger have a look at the <a href="http://help.blogger.com/bin/answer.py?hl=en&answer=112498#customizelayout">help site</a>.SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-87896965754847043022009-03-04T15:18:00.006+00:002009-08-10T14:07:02.070+01:00Adding ClearCase commands to Visual Studio context menuIf you are using Visual Studio and clearcase this is really useful. This puts clearcase functions like opening the version tree into the menu when you right click on a file in solution explorer.<br /><br />1. The following link shows you how to add new menu items to the context menu when you select file in the solution explorer:<br /><br /><a href="http://www.sharpregion.com/blog/?p=105&cpage=1">http://www.sharpregion.com/blog/?p=105&cpage=1</a><br /><br />2 . Just add the following bit of code to the module ContextCommads or download the full file from <a href="http://dl.getdropbox.com/u/427946/ContextCommands.vb">here</a>:<br /><br /><script src="http://friendpaste.com/4dqpST1QKSho22fwz5tKTA.js"></script><br /><br /><br />3. Now Repeat steps 7 to 9 from the afore mentioned link <a href="http://www.sharpregion.com/blog/?p=105&cpage=1">Extending the Visual-Studio Context-Menu</a> for the following three subs :<br /><br /><span style="font-weight: bold;">VersionTree </span>- this opens up the clearcase version tree for the selected file<br /><span style="font-weight: bold;">HijackFileCommand</span> - hjacks the selected file (makes it writeable)<br /><span style="font-weight: bold;">ClearCaseAnnotateCommand</span> - calls the clearcase annotate command to show who and when each change was made on the selected file<br /><br />Thats it. Now right click on a file and you will have these options availableSMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-77903689754684192792009-02-26T10:18:00.016+00:002009-08-17T11:31:53.194+01:00My top tools that every software developer should haveHere's my list of tools that make my day to day work a lot easier as a developer and some tools which are just useful to have on your desktop<br /><br /><span style="font-size:130%;"><a href="http://notepad-plus.sourceforge.net/">Notepadd ++</a></span><br /><br />Now this is the dog's dangly bits on text editors. It has built in syntax highlighters for nearly all formats, you can add your own syntax highlighters. You can open files in multiple tabs , firefox style and a whole host of other useful features. I use it for sql file edits, viewing log files , xml editing , batch file editing , etc , etc.<br /><br /><a href="http://notepad-plus.sourceforge.net/commun/screenshots/scrsh_lexerXML.gif"><img src="http://notepad-plus.sourceforge.net/commun/screenshots/scrsh_lexerXML_small.gif" /></a><br /><br />Free: <span style="font-weight: bold;">YES</span><a href="http://notepad-plus.sourceforge.net/uk/site.htm"><br />http://notepad-plus.sourceforge.net/uk/site.htm</a><br /><br /><span style="font-size:130%;"><a href="http://www.baremetalsoft.com/baregrep/">BareGrep</a></span><br /><br />The fastest file searcher I have found that's free! It can search through sub directories and use regexp if you need to. Very useful for search through tons of log files.<br /><br />Free : <span style="font-weight: bold;">YES </span>, but $25 USD version has a few more options<br /><a href="http://www.baremetalsoft.com/baregrep/">http://www.baremetalsoft.com/baregrep/</a><br /><br /><span style="font-size:130%;"><a href="http://www.baremetalsoft.com/baretail/index.php">BareTail</a></span><br /><br />Acts like a unix tail command but for windows. I.E. it monitors a text file and keeps updating whenever a new line is added. Perfect for log files. A nice feature is that it can highlight particular strings in whatever format you wish<br /><br />Free : <span style="font-weight: bold;">YES </span>, and $25 USD version also has a few more options<br /><a href="http://www.baremetalsoft.com/baretail/">http://www.baremetalsoft.com/baretail/</a><span style="font-weight: bold;"><br /><span style="font-size:130%;"><br /></span></span><span style="font-size:130%;"><a href="http://www.scootersoftware.com/">Beyond Compare</a></span><span style="font-weight: bold;"><br /></span><br />Definately the best file (and folder) comparison tool I have used. A perfect replacement to the crappy compare tool in clearcase (See my post <a href="http://randomconsultant.blogspot.com/2009/01/use-beyond-compare-in-clearcase.html">Use Beyond Compare in Clearcase</a>).<br /><br />Free : 30 day evaluation<br /><a href="http://www.scootersoftware.com/">http://www.scootersoftware.com/</a><br /><br /><span style="font-size:130%;"><a href="http://winmerge.org/">WinMerge</a></span><br /><br />If you don't want to shell out for Beyond Compare , winmerge is a pretty good substitute as it is open source, so yes it is free. One feature it does have that Beyond Compare doesn't is that it does code syntax highlighting in the comparison viewer.<br /><br />Free : <span style="font-weight: bold;">YES</span><a href="http://winmerge.org/"><br />http://winmerge.org/</a><br /><br /><span style="font-size:130%;"><a href="http://rocketdock.com/">RocketDock</a></span><br /><br />A thing to place your shortcuts, and makes your windows pc look a bit like a mac. Wow , other geeky developers . See the youtube vid.<br /><br /><object height="344" width="425"><param name="movie" value="http://www.youtube.com/v/d6UVb15it6A&hl=en&fs=1"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/d6UVb15it6A&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="344" width="425"></embed></object><br /><br />Free : <span style="font-weight: bold;">YES</span><br /><a href="http://rocketdock.com/">http://rocketdock.com/</a><br /><br /><span style="font-size:130%;"><br /><a href="http://www.executor.dk/">Executor</a></span><br /><br />A great application to start up any application installed. Very quick and intuitive to use.<br /><br /><img src="http://home25.inet.tele.dk/mb/executor/images/alphaskin.jpg" alt="Executor" /><br /><br />Free: <span style="font-weight: bold;">YES</span><br /><a href="http://www.executor.dk/">http://www.executor.dk/</a><br /><br /><span style="font-size:130%;"><a href="http://www.stardock.com/products/fences/">Fences</a></span><br /><br />Organise icons on your desktop into little areas called fences. Very useful<br /><br /><a href="http://www.stardock.com/products/fences/images/screenshots/DesktopFences_ss6.jpg"><img src="http://www.stardock.com/products/fences/images/screenshots/DesktopFences_ss6.jpg" height="172" width="275" /></a><br /><br />Free: <span style="font-weight: bold;">YES</span><br /><a href="http://www.stardock.com/products/fences/">http://www.stardock.com/products/fences/</a><br /><br /><span style="font-size:130%;"><a href="http://www.officerecovery.com/freeundelete/">FreeUndelete</a></span><br /><br />It does what is says on the tin! It undeletes file you thought you lost! Can be a lifesaver, actually it bailed me out today!.<br /><br />Free : <span style="font-weight: bold;">YES</span><br /><a href="http://www.officerecovery.com/freeundelete/">http://www.officerecovery.com/freeundelete/</a><br /><br /><span style="font-size:130%;"><a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx">Process Explorer</a></span><br /><br />It is a super replacement for windows task manager. Get detailed info on each process and easily see parent child processes.<br /><br /><img src="http://i.technet.microsoft.com/bb896653.ProcessExplorer%28en-us,MSDN.10%29.jpg" /><br /><br /><br />Free: <span style="font-weight: bold;">YES</span><br /><a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx">http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx</a><div><br /></div><div><span style="font-size:130%;"><a href="http://www.voidtools.com/">Everything Search Engine</a></span><br /><br />This is a really great tool to search for files . It is really lightweight and superfast. It indexes in the background , so when you search for something it is almost instant.</div><div><br /><br /><img src="http://www.voidtools.com/sssmall.jpg" alt="Search Everything" /></div><div><br /></div><div>Free : <b>YES</b></div><div><a href="http://www.voidtools.com/">http://www.voidtools.com/</a></div><div><br /></div><div><span class="Apple-style-span" style="font-size:7;"><span class="Apple-style-span" style="font-size: 48px;"><span class="Apple-style-span" style="font-size: 18px; "><a href="http://windirstat.info/">WinDirStat</a></span></span></span></div><div>If you are always running out of disk space, this is the tool for you. It shows you your big folders and files and has a nice little map of your drive.</div><div><br /></div><div>If you want something to work cross platform see some other suggestions from <a href="http://lifehacker.com/219058/geek-to-live--visualize-your-hard-drive-usage">lifehacker</a>:</div><div><br /></div><div><a href="http://lifehacker.com/219058/geek-to-live--visualize-your-hard-drive-usage">http://lifehacker.com/219058/geek-to-live--visualize-your-hard-drive-usage</a></div><div><br /></div><div><br /></div><br /><br /><a href="http://windirstat.info/images/windirstat.jpg"><img src="http://windirstat.info/images/windirstat-small.jpg" /></a><br /><br /><div><br /></div><div>Free : <b>YES</b></div><div><br /></div><div><a href="http://windirstat.info/">http://windirstat.info/</a></div><div><br /></div><div><br /></div><div><br /><br /></div><div><br /></div>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-48811084185780911692009-02-12T11:22:00.002+00:002009-02-12T11:37:52.610+00:00Facebook Connect on BloggerThis post is to test out using <a href="http://developers.facebook.com/connect.php">facebook connect</a> on blogger using <a href="http://disqus.com/">disqus</a>.<br /><br />So leave a comment and see what happens.<br /><br />I followed the instructions from:<br /><a href="http://manofmanywords.blogspot.com/2008/12/do-you-have-blog-on-blogger-wordpress.html"><br />http://manofmanywords.blogspot.com/2008/12/do-you-have-blog-on-blogger-wordpress.html</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.comtag:blogger.com,1999:blog-5599902997355913399.post-29911111071659069832009-01-26T21:56:00.004+00:002009-01-26T22:49:19.316+00:00Export SQL Server tables to Excel in c#This piece of code executes a sql query on a sql server database and returns the result into a excel workbook (with column headings included).<br /><br />Remember to add the following references (Project > Add Reference > COM)<br /><br />Microsoft Excel 12.0 Object Library (or an older version)<br /><br /><pre><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Collections</span>.<span style="color: rgb(32, 64, 160);">Generic</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Linq</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Text</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Data</span>.<span style="color: rgb(32, 64, 160);">SqlClient</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">Excel</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">Microsoft</span>.<span style="color: rgb(32, 64, 160);">Office</span>.<span style="color: rgb(32, 64, 160);">Interop</span>.<span style="color: rgb(32, 64, 160);">Excel</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Reflection</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">namespace</span> <span style="color: rgb(32, 64, 160);">ExportDBTablesToExcel</span><br /><span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>class</strong> <span style="color: rgb(32, 64, 160);">ExportToExcel</span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <strong>private</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Application</span> <span style="color: rgb(32, 64, 160);">app</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>private</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Workbook</span> <span style="color: rgb(32, 64, 160);">workbook</span><span style="color: rgb(68, 68, 255);">;</span><br /> <strong>private</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span> <span style="color: rgb(32, 64, 160);">previousWorksheet</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>private</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Range</span> <span style="color: rgb(32, 64, 160);">workSheet_range</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>private</strong> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">folder</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>private</strong> <strong>static</strong> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">CONNECTION_STR</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"Data Source=(local);Database=DATABASE_NAME;"</span><br /> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(0, 128, 0);">"Integrated Security=SSPI;"</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><br /> <strong>public</strong> <span style="color: rgb(32, 64, 160);">ExportToExcel</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">folder</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">folder</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">folder</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">app</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">workbook</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">previousWorksheet</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">workSheet_range</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /><br /> <span style="color: rgb(32, 64, 160);">createDoc</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>private</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">createDoc</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">app</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Application</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">app</span>.<span style="color: rgb(32, 64, 160);">Visible</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>false</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">workbook</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">app</span>.<span style="color: rgb(32, 64, 160);">Workbooks</span>.<span style="color: rgb(32, 64, 160);">Add</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">Write</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">e</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>finally</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>public</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">shutDown</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">workbook</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">app</span>.<span style="color: rgb(32, 64, 160);">Quit</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">Write</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">e</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>finally</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>public</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">ExportTable</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">query</span>,<span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">sheetName</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">SqlConnection</span> <span style="color: rgb(32, 64, 160);">myConnection</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">SqlConnection</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">CONNECTION_STR</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">SqlDataReader</span> <span style="color: rgb(32, 64, 160);">myReader</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span> <span style="color: rgb(32, 64, 160);">worksheet</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">workbook</span>.<span style="color: rgb(32, 64, 160);">Sheets</span>.<span style="color: rgb(32, 64, 160);">Add</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(255, 0, 0);">1</span>, <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">XlSheetType</span>.<span style="color: rgb(32, 64, 160);">xlWorksheet</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">worksheet</span>.<span style="color: rgb(32, 64, 160);">Name</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">sheetName</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">previousWorksheet</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">worksheet</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><br /><br /> <span style="color: rgb(32, 64, 160);">myConnection</span>.<span style="color: rgb(32, 64, 160);">Open</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(32, 64, 160);">SqlCommand</span> <span style="color: rgb(32, 64, 160);">myCommand</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">SqlCommand</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">query</span>,<br /> <span style="color: rgb(32, 64, 160);">myConnection</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">myReader</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">myCommand</span>.<span style="color: rgb(32, 64, 160);">ExecuteReader</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">columnCount</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">FieldCount</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>for</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><strong>int</strong> <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(68, 68, 255);">;</span> <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);"><</span> <span style="color: rgb(32, 64, 160);">columnCount</span><span style="color: rgb(68, 68, 255);">;</span> <span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">Write</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">GetName</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(0, 128, 0);">"<span style="color: rgb(119, 221, 119);">\t</span>"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">createHeaders</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">worksheet</span>, <span style="color: rgb(255, 0, 0);">1</span>, <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(255, 0, 0);">1</span>, <span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">GetName</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">rowCounter</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">2</span><span style="color: rgb(68, 68, 255);">;</span><br /> <strong>while</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">Read</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>for</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><strong>int</strong> <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(68, 68, 255);">;</span> <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);"><</span> <span style="color: rgb(32, 64, 160);">columnCount</span><span style="color: rgb(68, 68, 255);">;</span> <span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">Write</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">myReader</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">GetName</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(0, 128, 0);">"<span style="color: rgb(119, 221, 119);">\t</span>"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">addData</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">worksheet</span>, <span style="color: rgb(32, 64, 160);">rowCounter</span>, <span style="color: rgb(32, 64, 160);">n</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(255, 0, 0);">1</span>, <span style="color: rgb(32, 64, 160);">myReader</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">GetName</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">n</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(32, 64, 160);">rowCounter</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">e</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>finally</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>if</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">myReader</span><span style="color: rgb(68, 68, 255);">!</span><span style="color: rgb(68, 68, 255);">=</span><strong>null</strong> <span style="color: rgb(68, 68, 255);">&</span><span style="color: rgb(68, 68, 255);">&</span> <span style="color: rgb(68, 68, 255);">!</span><span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">IsClosed</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">myReader</span>.<span style="color: rgb(32, 64, 160);">Close</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>if</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">myConnection</span> <span style="color: rgb(68, 68, 255);">!</span><span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">myConnection</span>.<span style="color: rgb(32, 64, 160);">Close</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">myReader</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">myConnection</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /> <strong>public</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">createHeaders</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span> <span style="color: rgb(32, 64, 160);">worksheet</span>,<strong>int</strong> <span style="color: rgb(32, 64, 160);">row</span>, <strong>int</strong> <span style="color: rgb(32, 64, 160);">col</span>, <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">htext</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">worksheet</span>.<span style="color: rgb(32, 64, 160);">Cells</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">row</span>, <span style="color: rgb(32, 64, 160);">col</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">htext</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <strong>public</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">addData</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span> <span style="color: rgb(32, 64, 160);">worksheet</span>,<strong>int</strong> <span style="color: rgb(32, 64, 160);">row</span>, <strong>int</strong> <span style="color: rgb(32, 64, 160);">col</span>, <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">data</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">worksheet</span>.<span style="color: rgb(32, 64, 160);">Cells</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">row</span>, <span style="color: rgb(32, 64, 160);">col</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">data</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span> <br /><br /><br /> <strong>public</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">SaveWorkbook</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <br /> <span style="color: rgb(32, 64, 160);">String</span> <span style="color: rgb(32, 64, 160);">folderPath</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"C:<span style="color: rgb(119, 221, 119);">\\</span>My Files<span style="color: rgb(119, 221, 119);">\\</span>"</span> <span style="color: rgb(68, 68, 255);">+</span> <strong>this</strong>.<span style="color: rgb(32, 64, 160);">folder</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>if</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);">!</span><span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">IO</span>.<span style="color: rgb(32, 64, 160);">Directory</span>.<span style="color: rgb(32, 64, 160);">Exists</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">folderPath</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">IO</span>.<span style="color: rgb(32, 64, 160);">Directory</span>.<span style="color: rgb(32, 64, 160);">CreateDirectory</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">folderPath</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">fileNameBase</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"db"</span> <span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">String</span> <span style="color: rgb(32, 64, 160);">fileName</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">fileNameBase</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">ext</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">".xlsx"</span> <span style="color: rgb(68, 68, 255);">;</span><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">counter</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">1</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>while</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">IO</span>.<span style="color: rgb(32, 64, 160);">File</span>.<span style="color: rgb(32, 64, 160);">Exists</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">folderPath</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(32, 64, 160);">fileName</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(32, 64, 160);">ext</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">fileName</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">fileNameBase</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">counter</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">counter</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">fileName</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">fileName</span> <span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(32, 64, 160);">ext</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">filePath</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">folderPath</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">fileName</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">workbook</span>.<span style="color: rgb(32, 64, 160);">SaveAs</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">filePath</span>, <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">XlFileFormat</span>.<span style="color: rgb(32, 64, 160);">xlWorkbookDefault</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">XlSaveAsAccessMode</span>.<span style="color: rgb(32, 64, 160);">xlNoChange</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span>, <span style="color: rgb(32, 64, 160);">Missing</span>.<span style="color: rgb(32, 64, 160);">Value</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">e</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /> <strong>static</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">Main</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">string</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span> <span style="color: rgb(32, 64, 160);">args</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">ExportToExcel</span> <span style="color: rgb(32, 64, 160);">export</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">ExportToExcel</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">args</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">export</span>.<span style="color: rgb(32, 64, 160);">ExportTable</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"SELECT * FROM t_table1"</span>,<span style="color: rgb(0, 128, 0);">"t_table1"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">export</span>.<span style="color: rgb(32, 64, 160);">ExportTable</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"SELECT * FROM t_table2"</span>,<span style="color: rgb(0, 128, 0);">"t_table2"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">export</span>.<span style="color: rgb(32, 64, 160);">ExportTable</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"SELECT * FROM t_table3"</span>,<span style="color: rgb(0, 128, 0);">"t_table3"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">export</span>.<span style="color: rgb(32, 64, 160);">SaveWorkbook</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">export</span>.<span style="color: rgb(32, 64, 160);">shutDown</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /><br /><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /></pre>This code is based on the following links:<br /><a href="http://www.codeproject.com/KB/cs/Excel_and_C_.aspx"><br />http://www.codeproject.com/KB/cs/Excel_and_C_.aspx</a><br />and<br /><a href="http://www.codeproject.com/KB/database/sql_in_csharp.aspx?fid=16002&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=1490011">http://www.codeproject.com/KB/database/sql_in_csharp.aspx?fid=16002&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26&select=1490011</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com12tag:blogger.com,1999:blog-5599902997355913399.post-27752430509152016542009-01-21T12:21:00.003+00:002009-01-21T12:56:04.492+00:00Read an Excel document and Send an email from outlook in c# .netThis is a handy example if you need to read an excel document and/or send an email from outlook in some c# code.<br /><br />Remember to add the following references (Project > Add Reference > COM)<br /><br />Microsoft Excel 12.0 Object Library<br />Microsoft Office 12.0 Object Library<br />Microsoft Outlook 12.0 Object Library<br /><br />if you have older versions of office , they should work too.<br /><pre><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Collections</span>.<span style="color: rgb(32, 64, 160);">Generic</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Linq</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">System</span>.<span style="color: rgb(32, 64, 160);">Text</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">Excel</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">Microsoft</span>.<span style="color: rgb(32, 64, 160);">Office</span>.<span style="color: rgb(32, 64, 160);">Interop</span>.<span style="color: rgb(32, 64, 160);">Excel</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">Outlook</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">Microsoft</span>.<span style="color: rgb(32, 64, 160);">Office</span>.<span style="color: rgb(32, 64, 160);">Interop</span>.<span style="color: rgb(32, 64, 160);">Outlook</span><span style="color: rgb(68, 68, 255);">;</span><br /><span style="color: rgb(32, 64, 160);">using</span> <span style="color: rgb(32, 64, 160);">Microsoft</span>.<span style="color: rgb(32, 64, 160);">Office</span>.<span style="color: rgb(32, 64, 160);">Core</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /><span style="color: rgb(32, 64, 160);">namespace</span> <span style="color: rgb(32, 64, 160);">StatusNotifier</span><br /><span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>class</strong> <span style="color: rgb(32, 64, 160);">StatusNotifier</span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>static</strong> <strong>void</strong> <span style="color: rgb(32, 64, 160);">Main</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">string</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span> <span style="color: rgb(32, 64, 160);">args</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">Path</span> <span style="color: rgb(68, 68, 255);">=</span> @<span style="color: rgb(0, 128, 0);">"D:<span style="color: rgb(119, 221, 119);">\M</span>yExcelFile.xls"</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 68);">// initialize the Excel Application class</span><br /><br /> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">ApplicationClass</span> <span style="color: rgb(32, 64, 160);">app</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">ApplicationClass</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">// create the workbook object by opening the excel file.</span><br /> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Workbook</span> <span style="color: rgb(32, 64, 160);">workBook</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">app</span>.<span style="color: rgb(32, 64, 160);">Workbooks</span>.<span style="color: rgb(32, 64, 160);">Open</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Path</span>,<br /> <span style="color: rgb(255, 0, 0);">0</span>,<br /> <strong>true</strong>,<br /> <span style="color: rgb(255, 0, 0);">5</span>,<br /> <span style="color: rgb(0, 128, 0);">""</span>,<br /> <span style="color: rgb(0, 128, 0);">""</span>,<br /> <strong>true</strong>,<br /> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">XlPlatform</span>.<span style="color: rgb(32, 64, 160);">xlWindows</span>,<br /> <span style="color: rgb(0, 128, 0);">"<span style="color: rgb(119, 221, 119);">\t</span>"</span>,<br /> <strong>false</strong>,<br /> <strong>false</strong>,<br /> <span style="color: rgb(255, 0, 0);">0</span>,<br /> <strong>true</strong>,<br /> <span style="color: rgb(255, 0, 0);">1</span>,<br /> <span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">// get the active worksheet using sheet name or active sheet</span><br /> <span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span> <span style="color: rgb(32, 64, 160);">workSheet</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Worksheet</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">workBook</span>.<span style="color: rgb(32, 64, 160);">Worksheets</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">index</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">0</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 68);">// This row,column index should be changed as per your need.</span><br /> <span style="color: rgb(68, 68, 68);">// i.e. which cell in the excel you are interesting to read.</span><br /> <span style="color: rgb(32, 64, 160);">object</span> <span style="color: rgb(32, 64, 160);">rowIndex</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">2</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(32, 64, 160);">object</span> <span style="color: rgb(32, 64, 160);">colA</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">object</span> <span style="color: rgb(32, 64, 160);">colB</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">2</span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(32, 64, 160);">StringBuilder</span> <span style="color: rgb(32, 64, 160);">message</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">StringBuilder</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"My Message"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"--------------"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">""</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <span style="color: rgb(68, 68, 68);">//----------------------------</span><br /><br /> <span style="color: rgb(68, 68, 68);">//READ EXCEL WORKBOOK</span><br /> <span style="color: rgb(68, 68, 68);">//------------------------------</span><br /> <br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <strong>while</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Range</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">workSheet</span>.<span style="color: rgb(32, 64, 160);">Cells</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">rowIndex</span>, <span style="color: rgb(32, 64, 160);">colDateRaised</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span>.<span style="color: rgb(32, 64, 160);">Value2</span> <span style="color: rgb(68, 68, 255);">!</span><span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">rowIndex</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(255, 0, 0);">2</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">index</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">DateTime</span> <span style="color: rgb(32, 64, 160);">dateRaised</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">DateTime</span>.<span style="color: rgb(32, 64, 160);">FromOADate</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><strong>double</strong>.<span style="color: rgb(32, 64, 160);">Parse</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Range</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">workSheet</span>.<span style="color: rgb(32, 64, 160);">Cells</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">rowIndex</span>, <span style="color: rgb(32, 64, 160);">colA</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span>.<span style="color: rgb(32, 64, 160);">Value2</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">string</span> <span style="color: rgb(32, 64, 160);">description</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Excel</span>.<span style="color: rgb(32, 64, 160);">Range</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">workSheet</span>.<span style="color: rgb(32, 64, 160);">Cells</span><span style="color: rgb(68, 68, 255);"><strong>[</strong></span><span style="color: rgb(32, 64, 160);">rowIndex</span>, <span style="color: rgb(32, 64, 160);">colB</span><span style="color: rgb(68, 68, 255);"><strong>]</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span>.<span style="color: rgb(32, 64, 160);">Value2</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">rowIndex</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(0, 128, 0);">" DateRaised :"</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">dateRaised</span>.<span style="color: rgb(32, 64, 160);">ToShortDateString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(0, 128, 0);">"Description: "</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">description</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span> <span style="color: rgb(68, 68, 255);">;</span><br /><br /> <br /> <br /> <span style="color: rgb(32, 64, 160);">index</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">+</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">ex</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(32, 64, 160);">app</span>.<span style="color: rgb(32, 64, 160);">Quit</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">ex</span>.<span style="color: rgb(32, 64, 160);">Message</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"For more inforamtion please see:"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">AppendLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Path</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"Message:<span style="color: rgb(119, 221, 119);">\n</span> "</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(32, 64, 160);">message</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//----------------------------</span><br /> <span style="color: rgb(68, 68, 68);">//CREATE OUTLOOK MESSAGE</span><br /> <span style="color: rgb(68, 68, 68);">//------------------------------</span><br /> <br /> <strong>try</strong><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /> <span style="color: rgb(68, 68, 68);">// Create the Outlook application by using inline initialization.</span><br /><br /> <span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">Application</span> <span style="color: rgb(32, 64, 160);">oApp</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>new</strong> <span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">Application</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Create the new message by using the simplest approach.</span><br /> <span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">MailItem</span> <span style="color: rgb(32, 64, 160);">oMsg</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">MailItem</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">oApp</span>.<span style="color: rgb(32, 64, 160);">CreateItem</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">OlItemType</span>.<span style="color: rgb(32, 64, 160);">olMailItem</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Add a recipient.</span><br /> <span style="color: rgb(68, 68, 68);">// TODO: Change the following recipient where appropriate.</span><br /> <span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">Recipient</span> <span style="color: rgb(32, 64, 160);">oRecip</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">Recipient</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Recipients</span>.<span style="color: rgb(32, 64, 160);">Add</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"someone@somewhere.com"</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">oRecip</span>.<span style="color: rgb(32, 64, 160);">Resolve</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Set the basic properties.</span><br /> <span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Subject</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"Status Update"</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Body</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">message</span>.<span style="color: rgb(32, 64, 160);">ToString</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Add an attachment.</span><br /><br /> <span style="color: rgb(68, 68, 68);">// TODO: change file path where appropriate</span><br /> <span style="color: rgb(32, 64, 160);">String</span> <span style="color: rgb(32, 64, 160);">sSource</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"C:<span style="color: rgb(119, 221, 119);">\\</span>setupxlg.txt"</span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">String</span> <span style="color: rgb(32, 64, 160);">sDisplayName</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(0, 128, 0);">"MyFirstAttachment"</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">iPosition</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><strong>int</strong><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Body</span>.<span style="color: rgb(32, 64, 160);">Length</span> <span style="color: rgb(68, 68, 255);">+</span> <span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <strong>int</strong> <span style="color: rgb(32, 64, 160);">iAttachType</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><strong>int</strong><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">OlAttachmentType</span>.<span style="color: rgb(32, 64, 160);">olByValue</span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">Outlook</span>.<span style="color: rgb(32, 64, 160);">Attachment</span> <span style="color: rgb(32, 64, 160);">oAttach</span> <span style="color: rgb(68, 68, 255);">=</span> <span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Attachments</span>.<span style="color: rgb(32, 64, 160);">Add</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">sSource</span>, <span style="color: rgb(32, 64, 160);">iAttachType</span>, <span style="color: rgb(32, 64, 160);">iPosition</span>, <span style="color: rgb(32, 64, 160);">sDisplayName</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">// If you want to, display the message.</span><br /> <span style="color: rgb(68, 68, 68);">// oMsg.Display(true); //modal</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Send the message.</span><br /> <span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Save</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">oMsg</span>.<span style="color: rgb(32, 64, 160);">Send</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 68);">//Explicitly release objects.</span><br /> <span style="color: rgb(32, 64, 160);">oRecip</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(32, 64, 160);">oAttach</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">oMsg</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(32, 64, 160);">oApp</span> <span style="color: rgb(68, 68, 255);">=</span> <strong>null</strong><span style="color: rgb(68, 68, 255);">;</span><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /> <span style="color: rgb(68, 68, 68);">// Simple error handler.</span><br /> <strong>catch</strong> <span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(32, 64, 160);">Exception</span> <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>{</strong></span><br /><br /> <span style="color: rgb(32, 64, 160);">Console</span>.<span style="color: rgb(32, 64, 160);">WriteLine</span><span style="color: rgb(68, 68, 255);"><strong>(</strong></span><span style="color: rgb(0, 128, 0);">"{0} Exception caught: "</span>, <span style="color: rgb(32, 64, 160);">e</span><span style="color: rgb(68, 68, 255);"><strong>)</strong></span><span style="color: rgb(68, 68, 255);">;</span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /><br /><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /> <span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><span style="color: rgb(68, 68, 255);"><strong>}</strong></span><br /><br /></pre>This code is based upon examples from the following links:<br /><br />Excel: <a href="http://www.codeproject.com/KB/cs/Excel_Application_in_C_.aspx">http://www.codeproject.com/KB/cs/Excel_Application_in_C_.aspx</a><br />Outlook: <a href="http://support.microsoft.com/kb/310263">http://support.microsoft.com/kb/310263</a><br /><br /><a name="outlook"></a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com1tag:blogger.com,1999:blog-5599902997355913399.post-21621937424176895872009-01-20T16:04:00.002+00:002009-01-20T16:10:23.962+00:00Clearcase update from command line showing dialog and windowsIf you like doing things from the command line but you want the update progress bar , etc to pop up, then this is quite useful.<br /><br /><span style="font-size:85%;"><span style="font-family: courier new;">c:</span><br /><span style="font-family: courier new;">cd "C:\Program Files\Rational\ClearCase\bin"</span><br /><span style="font-family: courier new;">"clearviewupdate" -quick -window 1f00f4 -windowmsg c14e -ws </span><span style="font-style: italic; font-family: courier new;">"Path Here"</span></span><br /><br />If you don't want the update dialog to pop up you can use:<br /><br /><span style="font-size:85%;"><span style="font-family: courier new;">cleartool update </span><span style="font-style: italic; font-family: courier new;">"Path Here"</span></span>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com0tag:blogger.com,1999:blog-5599902997355913399.post-80449655668831505002009-01-15T14:59:00.005+00:002009-01-15T15:22:50.762+00:00Use Beyond Compare in ClearCaseIf you use any kind of source control system, one of the things you need to do is compare differences or "do diffs" or different versions of a file. However the the compare tool in clearcase is crap.<br /><br /><a href="http://www.scootersoftware.com/">Beyond Compare</a> is probably the the best file (and folder) comparison I have come across. It can even compare zip files.<br /><br />If you are tired of using the shitty compare tool that is a default in clearcase there is indeed a way to switch this to use beyond compare instead<br /><br />1. Go into the "<span style="font-weight: bold;">C:\Program Files\Rational\ClearCase\lib\mgrs</span>" directory.<br /><br />2. Create a backup of the file named "map".<br /><br />3. Edit "<span style="font-weight: bold;">map</span>" and change the line:<br /><code></code><pre>text_file_delta xcompare ..\..\bin\cleardiffmrg.exe</pre><br /> to:<br /><code></code><pre>text_file_delta xcompare C:\Progra~1\Beyond~1\bc2.exe</pre><br /><br />Thats it, next time you compare two versions of a file in the version tree or you compare with previous version, beyond compare will be used instead.<br /><br />Alternately if you want to use <a href="http://winmerge.org/">winmerge </a>(which is opensource and free) , then it gives you an option to replace the default viewer when you install it.SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com5tag:blogger.com,1999:blog-5599902997355913399.post-25113571108091378752009-01-13T13:03:00.013+00:002009-01-15T15:23:59.791+00:0025 most dangerous programming errorsA group of software people from various firms brought together by the <a href="http://en.wikipedia.org/wiki/National_Security_Agency">NSA</a> have sat around and come up with a list of the most dangerous 25 programming errors . If you been a developer for more than 5 minutes you have probably come across half of these, but this can be used as a handy checklist.<br /><br />In the words of Paul Kurtz, executive director of a group called the Software Assurance Forum for Excellence in Code "Now, with the Top 25, we can spend less time working with police after the house has been robbed and instead focus on getting locks on the doors before it happens"<br /><br />Here's my cheap and cheerful run down of through the list.<br /><br /><span style="font-style: italic;font-size:85%;" >Each heading links to the site where there is more detail on each , which includes discussion, prevention and mitagations, attack patterns against the error.</span><br /><br /><span style="color: rgb(255, 0, 0);"><span style="font-style: italic;"><span style="font-weight: bold;">15-Jan-08: I haven't had time to comment on each error in the list, but I will do at some point</span></span></span><br /><br /><span style="font-size:100%;"> 1</span>. <a href="http://cwe.mitre.org/top25/#CWE-20">Improper Input Validation</a><br />e.g. Alpha characters aren't allowed to be entered in numeric fields, stuff like that<br /><span style="font-size:100%;"> 2</span>. <a href="http://cwe.mitre.org/top25/#CWE-116">Improper Encoding or Escaping of Output</a><br />Using stored procs and using correct character encoders<br />3. <a href="http://cwe.mitre.org/top25/#CWE-89">Failure to Preserve SQL Query Structure (aka 'SQL Injection')</a><br />Make sure a user can't enter sql into a text field that will<br />4. <a href="http://cwe.mitre.org/top25/#CWE-79">Failure to Preserve Web Page Structure (aka 'Cross-site Scripting')</a><br />5. <a href="http://cwe.mitre.org/top25/#CWE-78">Failure to Preserve OS Command Structure (aka 'OS Command Injection')</a><br />6. <a href="http://cwe.mitre.org/top25/#CWE-319">Cleartext Transmission of Sensitive Information</a><br />7. <a href="http://cwe.mitre.org/top25/#CWE-352">Cross-Site Request Forgery (CSRF)</a><br />8. <a href="http://cwe.mitre.org/top25/#CWE-362">Race Condition</a><br />9. <a href="http://cwe.mitre.org/top25/#CWE-209">Error Message Information Leak</a><br />10. <a href="http://cwe.mitre.org/top25/#CWE-119">Failure to Constrain Operations within the Bounds of a Memory Buffer</a><br />11. <a href="http://cwe.mitre.org/top25/#CWE-642">External Control of Critical State Data</a><br />12. <a href="http://cwe.mitre.org/top25/#CWE-73">External Control of File Name or Path</a><br />13. <a href="http://cwe.mitre.org/top25/#CWE-426">Untrusted Search Path</a><br />14. <a href="http://cwe.mitre.org/top25/#CWE-94">Failure to Control Generation of Code (aka 'Code Injection')</a><br />15. <a href="http://cwe.mitre.org/top25/#CWE-494">Download of Code Without Integrity Check</a><br />16. <a href="http://cwe.mitre.org/top25/#CWE-404">Improper Resource Shutdown or Release</a><br />17. <a href="http://cwe.mitre.org/top25/#CWE-665">Improper Initialization</a><br />18. <a href="http://cwe.mitre.org/top25/#CWE-682">Incorrect Calculation</a><br />19. <a href="http://cwe.mitre.org/top25/#CWE-285">Improper Access Control (Authorization)</a><br />20.<a href="http://cwe.mitre.org/top25/#CWE-327"> Use of a Broken or Risky Cryptographic Algorithm</a><br />21. <a href="http://cwe.mitre.org/top25/#CWE-259">Hard-Coded Password</a><br />22. <a href="http://cwe.mitre.org/top25/#CWE-732">Insecure Permission Assignment for Critical Resource</a><br />23. <a href="http://cwe.mitre.org/top25/#CWE-330">Use of Insufficiently Random Values</a><br />24.<a href="http://cwe.mitre.org/top25/#CWE-250"> Execution with Unnecessary Privileges</a><br />25. <a href="http://cwe.mitre.org/top25/#CWE-602">Client-Side Enforcement of Server-Side Security</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com0tag:blogger.com,1999:blog-5599902997355913399.post-6941996886348547902009-01-06T08:41:00.005+00:002009-08-10T14:07:24.798+01:00Remote Debugging a .NET app with Visual Studio 2008 (9)This is where you need to debug an application in visual studio, but the process is running on some other machine (i.e. not on your local box). A good example is when a tester is running something and you want to connect to their box to debug it.<br /><br />This in fact turned out to be a pretty painless process.<br /><br />First on the machine where the app is running that you need to debug you need to run <span style="font-weight: bold;">msvsmon.exe</span> . I found this in <span style="font-style: italic;"><br /><br />Program Files</span>\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86 .<br /><br />This will bring up the "Visual Studio Remote Debugging Monitor".<br /><br />More than likely you will be debugging a machine on your network. So goto <span style="font-weight: bold;">Tools>Permissions</span>, and add the user of the machine where visual studio is running.<br /><br />Now run the application you intened to debug<br /><br />Now in Visual Studio goto <span style="font-weight: bold;">Debug>Attach to Process</span> . In the box "Qualifier" , enter the machine name of where your application is running and hit enter.<br /><br />A list of processes will appear in the "Available Processes" box below. On the other machine in the remote debugging monitor you will see a log that you have connected.<br /><br />Select the process which corresponds to the app you want to debug from Available processes and click on attach. And that's it you are now in debug mode and you can set your breakpoints and whatever and debug your app in the usual way!<br /><br />For more info look at this article from microsoft :<br /><br /><a href="http://support.microsoft.com/kb/910448">http://support.microsoft.com/kb/910448</a>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com3tag:blogger.com,1999:blog-5599902997355913399.post-1518349871075009062008-11-27T09:59:00.002+00:002008-11-27T10:04:05.488+00:00Oh my GOSWhat are the f***ing system requirements for <a href="http://www.thinkgos.com/dgadgets.php">GOS 3</a> ?<br /><br />According to the link above it's x86 1GHZ , 256Mb Ram . But I tried installing this on a laptop that is 2GHz with 256Mb Ram and on the first step of the installer on the live cd (where you select the language) , everything just froze :-(<br /><br />If anybody else has had this problem and knows what to do, please leave a comment!SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com0tag:blogger.com,1999:blog-5599902997355913399.post-54081517837405308102008-10-29T13:21:00.003+00:002008-10-29T13:35:59.059+00:00SQL Server Cascade DeleteJust came across one of the most useful scripts ever! It can be a real pain in the arse when you need to delete some data from a table , then find out that some data somewhere else depends upon what you want to delete, and some data somewhere else relies on that, and so on and so on.<br /><br />Well this script from <a href="http://www.sqlteam.com/forums/pop_profile.asp?mode=display&id=3203">Tim Young</a>, creates a stored procedure that does everything for you. You just pass it the name of your table and some criteria (like user='bob') and it will delete all the referencing data and also print out the DELETE statements it created.<br /><br />See the link below for a full example and explanation<br /><a href="http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7">http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7</a><br /><br />But if you can't wait and just want to see the store procedure, here you go<br /><br/><br /><br />P.S. I got this to work on SQLServer 2005.<br /><br /><P>Here’s the code for the procedure:<br /><br /><br /><br /><br /><pre class="code"><font color=Blue>CREATE</font> <font color=Blue>Procedure</font> spDeleteRows<br /><font color=Green>/* <br />Recursive row delete procedure. <br /><br />It deletes all rows in the table specified that conform to the criteria selected, <br />while also deleting any child/grandchild records and so on. This is designed to do the <br />same sort of thing as Access's cascade delete function. It first reads the sysforeignkeys <br />table to find any child tables, then deletes the soon-to-be orphan records from them using <br />recursive calls to this procedure. Once all child records are gone, the rows are deleted <br />from the selected table. It is designed at this time to be run at the command line. It could <br />also be used in code, but the printed output will not be available.<br />*/</font><br /> (<br /> @cTableName <font color=Blue>varchar</font>(50), <font color=Green>/* name of the table where rows are to be deleted */</font><br /> @cCriteria <font color=Blue>nvarchar</font>(1000), <font color=Green>/* criteria used to delete the rows required */</font><br /> @iRowsAffected <font color=Blue>int</font> OUTPUT <font color=Green>/* number of records affected by the delete */</font><br /> )<br /><font color=Blue>As</font><br /><font color=Blue>set</font> <font color=Blue>nocount</font> <font color=Blue>on</font><br /><font color=Blue>declare</font> @cTab <font color=Blue>varchar</font>(255), <font color=Green>/* name of the child table */</font><br /> @cCol <font color=Blue>varchar</font>(255), <font color=Green>/* name of the linking field on the child table */</font><br /> @cRefTab <font color=Blue>varchar</font>(255), <font color=Green>/* name of the parent table */</font><br /> @cRefCol <font color=Blue>varchar</font>(255), <font color=Green>/* name of the linking field in the parent table */</font><br /> @cFKName <font color=Blue>varchar</font>(255), <font color=Green>/* name of the foreign key */</font><br /> @cSQL <font color=Blue>nvarchar</font>(1000), <font color=Green>/* query string passed to the sp_ExecuteSQL procedure */</font><br /> @cChildCriteria <font color=Blue>nvarchar</font>(1000), <font color=Green>/* criteria to be used to delete <br /> records from the child table */</font><br /> @iChildRows <font color=Blue>int</font> <font color=Green>/* number of rows deleted from the child table */</font><br /><br /><font color=Green>/* declare the cursor containing the foreign key constraint information */</font><br /><font color=Blue>DECLARE</font> cFKey <font color=Blue>CURSOR</font> LOCAL <font color=Blue>FOR</font> <br /><font color=Blue>SELECT</font> SO1.name <font color=Blue>AS</font> Tab, <br /> SC1.name <font color=Blue>AS</font> Col, <br /> SO2.name <font color=Blue>AS</font> RefTab, <br /> SC2.name <font color=Blue>AS</font> RefCol, <br /> FO.name <font color=Blue>AS</font> FKName<br /><font color=Blue>FROM</font> dbo.<font color=Brown>sysforeignkeys</font> FK <br /><font color=Blue>INNER</font> <font color=Blue>JOIN</font> dbo.<font color=Brown>syscolumns</font> SC1 <font color=Blue>ON</font> FK.fkeyid = SC1.id <br /> <font color=Blue>AND</font> FK.fkey = SC1.colid <br /><font color=Blue>INNER</font> <font color=Blue>JOIN</font> dbo.<font color=Brown>syscolumns</font> SC2 <font color=Blue>ON</font> FK.rkeyid = SC2.id <br /> <font color=Blue>AND</font> FK.rkey = SC2.colid <br /><font color=Blue>INNER</font> <font color=Blue>JOIN</font> dbo.<font color=Brown>sysobjects</font> SO1 <font color=Blue>ON</font> FK.fkeyid = SO1.id <br /><font color=Blue>INNER</font> <font color=Blue>JOIN</font> dbo.<font color=Brown>sysobjects</font> SO2 <font color=Blue>ON</font> FK.rkeyid = SO2.id <br /><font color=Blue>INNER</font> <font color=Blue>JOIN</font> dbo.<font color=Brown>sysobjects</font> FO <font color=Blue>ON</font> FK.constid = FO.id<br /><font color=Blue>WHERE</font> SO2.Name = @cTableName<br /><br /><font color=Blue>OPEN</font> cFKey<br /><font color=Blue>FETCH</font> NEXT <font color=Blue>FROM</font> cFKey <font color=Blue>INTO</font> @cTab, @cCol, @cRefTab, @cRefCol, @cFKName<br /><font color=Blue>WHILE</font> <font color=Fuchsia>@@FETCH_STATUS</font> = 0<br /> <font color=Blue>BEGIN</font><br /> <font color=Green>/* build the criteria to delete rows from the child table. As it uses the <br /> criteria passed to this procedure, it gets progressively larger with <br /> recursive calls */</font><br /> <font color=Blue>SET</font> @cChildCriteria = @cCol + ' <font color=Blue>in</font> (<font color=Blue>SELECT</font> [' + @cRefCol + '] <font color=Blue>FROM</font> [' + <br /> @cRefTab +'] <font color=Blue>WHERE</font> ' + @cCriteria + ')'<br /> <font color=Blue>print</font> 'Deleting records <font color=Blue>from</font> <font color=Blue>table</font> ' + @cTab<br /> <font color=Green>/* call this procedure to delete the child rows */</font><br /> <font color=Blue>EXEC</font> spDeleteRows @cTab, @cChildCriteria, @iChildRows OUTPUT<br /> <font color=Blue>FETCH</font> NEXT <font color=Blue>FROM</font> cFKey <font color=Blue>INTO</font> @cTab, @cCol, @cRefTab, @cRefCol, @cFKName<br /> <font color=Blue>END</font><br /><font color=Blue>Close</font> cFKey<br /><font color=Blue>DeAllocate</font> cFKey<br /><font color=Green>/* finally delete the rows from this table and display the rows affected */</font><br /><font color=Blue>SET</font> @cSQL = '<font color=Blue>DELETE</font> <font color=Blue>FROM</font> [' + @cTableName + '] <font color=Blue>WHERE</font> ' + @cCriteria<br /><font color=Blue>print</font> @cSQL<br /><font color=Blue>EXEC</font> sp_ExecuteSQL @cSQL<br /><font color=Blue>print</font> 'Deleted ' + <font color=Fuchsia>CONVERT</font>(<font color=Blue>varchar</font>, <font color=Fuchsia>@@ROWCOUNT</font>) + ' records <font color=Blue>from</font> <font color=Blue>table</font> ' + @cTableName</pre><br /><br /><p>In the above scenario, we were trying to perform the following : <br /><pre class="code"> DELETE FROM X WHERE field1 = '234'</pre><br /><P>Using this procedure, we would use the following command:<br /><pre class="code"> exec spDeleteRows 'X', 'field1 = ''234''', 0</pre>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com2tag:blogger.com,1999:blog-5599902997355913399.post-73898218177944627192008-07-28T13:34:00.007+01:002008-07-28T15:49:12.494+01:00Not so warm for cuil<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN7tASWOK60zvXpTYJmfUAUv20IIohZ9KubGHzP3j9NHkVpL49m6QihZl6oCkBvYy9EXJlaN8NaLHWOZZrrSiq1GxPlKTSJ6T8JxnMWPJK-VsQmmuIYHcMp_afP4rcnpqgnliaO1aMCuY/s1600-h/cuil_screenshot.jpg"><img id="BLOGGER_PHOTO_ID_5228043445017188050" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: pointer; TEXT-ALIGN: center" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN7tASWOK60zvXpTYJmfUAUv20IIohZ9KubGHzP3j9NHkVpL49m6QihZl6oCkBvYy9EXJlaN8NaLHWOZZrrSiq1GxPlKTSJ6T8JxnMWPJK-VsQmmuIYHcMp_afP4rcnpqgnliaO1aMCuY/s320/cuil_screenshot.jpg" border="0" /></a>The<a href="http://news.bbc.co.uk/1/hi/technology/7528503.stm"> top technology story on the bbc</a> today was a new search "rival" to google. I was going to dismiss it, but I caught the line where it said it is developed by former employees from the big G.<br /><br />The name of this new search engine <a href="http://www.cuil.com/">Cuil </a>, pronounced Cool means knowledge in Gaelic, but who cares, is it any better than good ol' google?<br /><br />First thing I noticed when I entered the site, was the blackness, in contrast to googles white nothingness. Also it took a few moments to come up, I think it may have come up with a loading screen for a second.<br /><br />I searched for this blog <a href="http://randomconsultant.blogspot.com/">randomconsultant</a> and it didn't have it listed. That was slightly disapointing, as their crawler technology is suppose to be better than google's. But hey it's their first day and this is an little known blog.<br /><br />But <a href="http://www.cuil.com/info/">Cuil does claim that it searches more pages on the web than anyone else </a>- three times as many as google and ten times as many as microsoft.<br /><br />I then searched for something more likely, like the firm I work for. That did come up and the thing that stands out is that the search results were in two columns and each had a little thumbnail. Some of the thumbnails didn't really match the result and there were too many results for pages from the same site.<br /><br />On the right it had some categories.. but pratically speaking one wants their search engine to contain what they want in the first 3 hits, who cares about other categories. I remember dogpile.com(use to collect google,yahoo and other searches) had a similar thing but I never used it then.<br /><br />The results didn't come up that quickly too, which maybe because the whole web wants to check out a possible google killer. In fact Cuil and cuil.com are number one and two respectively in the hottest <a href="http://www.google.com/trends/hottrends?sa=X">Google Trends</a> list (i.e. the most searched for keywords right now) . I am sure google love that.<br /><br />The search technology cuil uses is suppose to be a lot more sophicticated than google. Instead of just looking at which pages link to what like google does, it also looks at the context of the page and probably other stuff.<br /><br />I will reserve complete judgement for now, until cuil has a bit of time to crawl the web, but I can't see anything now that will really trouble or make me and others want to switch their homepage.<br /><br />Maybe in the future, when I am searching for some obscure things and google is firing blanks, and cuil comes up trumps maybe I will switch, but right now I don't think anybody will be in line to jump out of the windows at google hq.<br /><br /><span style="FONT-WEIGHT: bold">STOP PRESS:</span><br /><br />Just tried going to <a href="http://www.cuil.com/">cuil.com</a> and I got this message<br /><div id="bdy"><h2></h2><blockquote><h2>"We’ll be back soon...</h2><p>Due to overwhelming interest, our Cuil servers are running a bit hot right now. The search engine is momentarily unavailable as we add more capacity.</p><p>Thanks for your patience."</p></blockquote><p></p><p>As the US starts waking up looks like they are on overload.... wonder how long people will use it... maybe for the novelty factor... or mayber it will be just "cuiler" (ok that's bad) than googling!<br /></p><p></p></div>SMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com0tag:blogger.com,1999:blog-5599902997355913399.post-7635229935880994222008-07-28T09:42:00.007+01:002008-07-30T08:59:56.382+01:00IBM buy ILOG!Just heard that IBM have swallowed up another product! Apparently this will provide ILOG customers with <blockquote>"a full set of rule management tools for complete information and application lifecycle management across a comprehensive platform including IBM's leading WebSphere application development and management platform."</blockquote><br />This basically means RSA will probably come bundled with JRules and projects will probably be encouraged (forced) to go with websphere if they choose to go with JRules.<br /><br />I just find this quite funny, as for the last couple of years on my project, ILOG have complained websphere is no good, the IBM jdk is no good, and the rule studio plugin doesn't play well with RSA. IBM have complained that JRules has a ton of peformance issues and a whole load of other stuff.<br /><br />I wonder what the guys at JBoss think. Before this they were the only ones who could provide a complete suite of application server and rules etc.<br /><br />So this will probably bring ILOG into the mainstream, so nowhere is safe from the bpm and brms!<br /><br /><br />Futher reading:<br /><br /><a href="http://smartenoughsystems.com/wp/2008/07/28/first-thoughts-on-the-ibmilog-announcement/">First thoughts on the IBM/ILOG announcement</a> by James Taylor - more of an in depth serious look at it than me.<br /><a href="http://www.onstrategies.com/blog/?p=333">IBM Puts the Rules Down</a> - OnStrategies.<br /><a href="http://www.ilog.com/corporate/releases/us/080728_ibm.cfm">ILOG Press release</a><br /><a href="http://www.theregister.co.uk/2008/07/28/ibm_buys_ilog/">IBM throws arms around ILOG</a> - The RegisterSMhttp://www.blogger.com/profile/12739561458581174311noreply@blogger.com0