Snippets and info

A collection of useful bits of code, advice and informative advice

Wednesday, February 08, 2006

Compilier directive attributes.

Add the attribute [MethodImplAttribute(MethodImplOptions.NoInlining)] to a c# method to stop the compiler inlining it.

Thursday, August 18, 2005

How to create an event for a ASP.Net Page

To create an Event for a Asp.Net Page or Control you need the following elements:

1. The event object

private static readonly object EventFoo = new object();

2. The EventHandler (that you will add delegates to)
[Description(""), Category("Action")]
public event EventHandler Foo
{
add
{
base.Events.AddHandler (FooPage.EventFoo, value);
}
remove
{
base.Events.RemoveHandler (FooPage.EventFoo, value);
}
}

3. OnFoo is the method that will be invoked whenever the event is to be fired. protected virtual void OnFoo (EventArgs e)
{
if (this.Events != null)
{
EventHandler handler = (EventHandler) Events[FooPage.EventFoo];
if (handler != null)
{
handler(this, e);
}
}
}

Now you can add handlers to Foo as you would with any other Event (for example Page_Load)

Monday, May 16, 2005

Slashdot | Could Microsoft Buy Red Hat?

Spotted on the Slashdot blog Slashdot | Could Microsoft Buy Red Hat?: "Re:GPL? (Score:5, Funny)
by Anonymous Coward on Monday May 16, @02:37PM (#12545816)

If Microsoft bought Red Hat, wouldn't this mean that Microsoft would be under the GPL when it comes to releasing software?

I'm glad you asked that, because I collect stupid questions and I hadn't seen that one before.

Friday, April 22, 2005

Stock, Fonts and more...

Just some links...

Wednesday, December 08, 2004

Showing background colors in Internet Explorer via CSS

A common question is how to force background colors to show when printing web sites. Normally the answer is; you can't but by using an IE filter such as the following the desired effect can be reached:


filter:progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#ff6600,endColorStr=#ff6600);
This background will be visible in Print Preview
This background will Not be visible in Print Preview

Some things to remember:

  • It's IE only (but then that is 9 out of 10 browsers overall and for most non techie commercial sites even higher).
  • You may need to define a height to the container tag (via the tag or css).
  • This will not work on all tags, for example div, p, h1 etc..., table all work but tr's will not.

Monday, November 22, 2004

Migrate SQL Server Script

Here's a nice script that a colleague found takes the grunt work out of transfering data from one database to another. After running this (and changing the SourceDatabase and TargetDatabase variables) you'll get a set of insert scripts that you can copy n' paste (with a little clean up if there were any schema changes between the two databases) and run on your server (at your own risk ;) ).

Certainly takes the grunt work out of migrating a database.

DECLARE @data_source varchar(8000)
DECLARE @data_target varchar(8000)

SELECT @data_source = 'SourceDataBase'
SELECT @data_target = 'TargetDataBase'

DECLARE @table_name varchar(8000)
DECLARE table_cursor CURSOR FOR
SELECT sysobjects.name FROM sysobjects WHERE sysobjects.xtype = 'U' AND sysobjects.name <> 'dtproperties'

OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @table_name
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @column_list varchar(8000)
SELECT @column_list = ''
DECLARE @column_identity bit
SELECT @column_identity = 0

DECLARE @column_name varchar(8000)
DECLARE @column_status tinyint

DECLARE column_cursor CURSOR FOR
SELECT syscolumns.name, syscolumns.status FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id WHERE sysobjects.xtype = 'U' AND sysobjects.name = @table_name

OPEN column_cursor
FETCH NEXT FROM column_cursor INTO @column_name, @column_status
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @column_list = (@column_list + '[' + @column_name + '], ')
IF ((@column_status & 128) = 128) SELECT @column_identity = 1
FETCH NEXT FROM column_cursor INTO @column_name, @column_status
END

CLOSE column_cursor
DEALLOCATE column_cursor
IF (@column_identity = 1) PRINT 'SET IDENTITY_INSERT ['+ @table_name + '] ON' PRINT 'INSERT INTO [' + @data_target + ']..[' + @table_name + '] (' + LEFT(@column_list, LEN(@column_list) - 1) + ') SELECT ' + LEFT(@column_list, LEN(@column_list) - 1) + ' FROM [' + @data_source + ']..[' + @table_name + ']'
IF (@column_identity = 1) PRINT 'SET IDENTITY_INSERT ['+ @table_name + '] OFF'
FETCH NEXT FROM table_cursor INTO @table_name
END
CLOSE table_cursor
DEALLOCATE table_cursor

Thursday, October 28, 2004

Korby Parnell's WebLog - Visual SourceSafe

Interesting site on Visual Sourcesafe - hopefully will be useful to the 'Bugaloo' project. Korby Parnell's WebLog - Visual SourceSafe