Monday 8 August 2011

IE9 Javascript change

I ran into a problem where by a piece of positioning Javascript that worked in all browser including IE 8 did not work in IE9.  "style.top" did not work under IE9 !

The original code was this...

ele.style.top = (a - b);

I had to change it to...

ele.style.tp = (a - b).toString() + 'px';

Wednesday 18 May 2011

Avoid Collation Issues

I had yet another query where the difference in the collation between my development database and tempdb that caused a TSQL error to be thrown.

The answer was to "collation proof" the query. It was really simple, you add the collation to be used into the query itself! below is the example.

WHERE #RawData.FullName = DiscrepancyReport.FullName COLLATE SQL_Latin1_General_CP1_CI_AS

Monday 18 April 2011

Encoding images into HTML using C#

Here's a sample that converts a jpeg into an imline image tag...


using System;
using System.IO;
using System.Drawing;
namespace ImageToBase64
{
class Program
{
static void Main(string[] args)
{
using(System.Drawing.Image i = (Image)Bitmap.FromFile(@"c:\test\TMC_logo_2.jpg"))
{
using(MemoryStream ms = new MemoryStream())
{
i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes = ms.ToArray();
string s = Convert.ToBase64String(bytes);
using(TextWriter tw = new StreamWriter(@"c:\test\string.txt"))
{
tw.WriteLine(string.Format(@"", s));
}
}
}
}
}
}

Friday 11 February 2011

WatiN Samples

Accessing an HTML Table, which gives access to rows and columns

WatiN.Core.Table tbl = this.IE.Table(Find.ById("ctl00_bodyContentPlaceHolder_GridView"));

Typing into text field

this.IE.TextField(Find.ByName("ctl00$bodyContentPlaceHolder$Name")).TypeText(CompanyName);