Skip to content

Checking if the file is locked

A post that I had found recently on Stack Overflow which answers the following question which often happens when you see “File in use by another process” proves quite useful in C# :-

I’m writing a program in C# that needs to repeatedly access 1 image file. Most of the time it works, but if my computer’s running fast, it will try to access the file before it’s been saved back to the filesystem and throw an error: “File in use by another process”.

Here’s the code to check based on the FileInfo property of a file is a file is locked or not which works.

protected virtual bool IsFileLocked(FileInfo file)
FileStream stream = null;

stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
catch (IOException)
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
if (stream != null)

//file is not locked
return false;

Grove Starter Kit for Arduino


Grove Starter Kit for Arduino!!

Originally posted on Chris Swan's Weblog:

When I first saw the LinkIt ONE at Mediatek’s stand at the Web Summit it was being shown of with a bunch of neat modular peripherals. The person on the stand had no idea about them, and couldn’t explain why the board had its own connectors for these modules. It didn’t take much sleuthing to discover that the modular system was Seeed Studio’s Grove system[1], and I ordered myself a Grove Starter Kit (for Arduino[2])

The kit comes with a bunch of sensors and actuators. It’s much like what can be found in an Arduino starter kit like the ARDX, but the key is that everything is connected together with the same 4 wire leads rather than having to plug individual components and wires into breadboard.

The simplicity of connection makes prototyping much quicker and easier, so I think the Grove kit does a good job of making…

View original 58 more words

How to get the current row selected in a HTML5 table in JQuery

If you have a table called #tblSummary with lots of rows and columns, you can grab hold of the row clicked if you have a a link or button within that row using JQuery by using the event handler $(‘#tblSummary’).find(‘tr’).click(function())

If you call $(this), you are able to get hold of the selected table rowm and be able to drill down to any of the column cells of that row using $(this).find(“td:first”).html() to get the first column cell in HTML format or $(this).find(“td:nth-child(2)”).html() to get the second column cell in HTML format.

See code below for an example.

if ($(“.fieldValue”).val() == “False”) {

$(‘#container-5′).tabs(“select”, 0);

if ($(“.fieldValue”).val() == “True”) {
$(‘#container-5′).tabs(“select”, 1);

$(‘#tblSummary’).find(‘tr’).click(function () {
var content = $(this).find(“td:nth-child(2)”).html();
if (content.indexOf(“tab1″) >= 0) {
$(‘#tabs’).tabs(“select”, 0);
$(“.fieldValue”).value = “False”;
if (content.indexOf(“tab2″) >= 0) {
$(‘#tabs’).tabs(“select”, 1);
$(“.fieldValue”).value = “True”;

Get Todays Date In Javascript

Here’s a very quick tip to get todays date in Javascript, heres the code to do so: -

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();

if (dd < 10) {
dd = ‘0’ + dd;

if (mm < 10) {
mm = ‘0’ + mm;

today = mm + ‘/’ + dd + ‘/’ + yyyy;


So it should show 10/31/2014

How to save a HTML5 canvas as a downloaded image and name the file

I had been trying to find a way to save a HTML5 canvas object as an image but also to nbame it to your preference which was not an easy find on the web to do. Luckily I have found something in Chrome that can do this by saving the file as an PNG of the selected HTML5 canvas but also to name the file as test.png

Here’s how: -

        var ua = window.navigator.userAgent;
        if (ua.indexOf("Chrome") > 0) {
            // save image without file type
            var canvas = document.getElementById("canvas");
            document.location.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
            // save image as png
            var link = document.createElement('a');
   = "test.png";
            link.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");;
        else {
            alert("Please use Chrome");

Useful Tip for getting HTML component tags by class name

Here is a quick tip for getting HTML component tags by class name.

To do this, you need to call the getElementsByClassName with the class name, and as the result is stored as an object array, you call the nth element, e.g the first element is called y[0], and to get the HTML content, you use innerHTML. If there is more than one element with the same name, you call y[1] etc.

See below.

var y = document.getElementsByClassName(“SmallTabSelected”);
var getValue = y[0].innerHTML;

How to allow SQL Server Agent to be run

If you receive the error message “Ad hoc update to system catalogs is not supported” when trying to activate the SQL Server Agent and the message “SQL Server blocked access to procedure ‘dbo.sp_sqlagent_get_startup_info’ of component ‘Agent XPs'”
You need to run the following commands to fix the issue

Allow updates is used to set up direct ad-hoc updates to system catalogs and tables. This is set to default to 0, but for some instances, it may have been set to 1 beforehand, so here you are setting it back to 0.

EXEC sp_configure ‘allow updates’

You can then enable the use of Agent Xps by using sp_configure because SQL Server blocked access to procedure ‘dbo.sp_sqlagent_get_startup_info’ of component ‘Agent XPs’ because this component is turned off due to security. You can enable it by the following:-

sp_configure ‘show advanced options’, 1;
sp_configure ‘Agent XPs’, 1;


Get every new post delivered to your Inbox.

Join 482 other followers