 |
DateTime.ToString() Patterns
Paul Hayman (444205 views)
DateTime.ToString() Patterns
All the patterns:
||0|| MM/dd/yyyy|| 08/22/2006 ||
||1|| dddd, dd MMMM yyyy|| Tuesday, 22 August 2006 ||
||2|| dddd, dd MMMM yyyy|| HH:mm Tuesday, 22 August 2006 06:30 ||
||3|| dddd, dd MMMM yyyy|| hh:mm tt Tuesday, 22 August 2006 06:30 AM ||
||4|| dddd, dd
|
 |
URL Regular Expression
Paul Hayman (71478 views)
URL Regular Expression
#c#string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"
#c#
|
 |
Creating a Tag Cloud in C#
Paul Hayman (45187 views)
Creating a Tag Cloud in C#
I wanted to add a TagCloud to GeekZilla and another {bespoke development}http://www.kwiboo.com/Services/Bespoke-Development project. The first thing I did was look around the web for some examples (or free components). To my supprise none jumped out at me. So, I decid
|
 |
Launching an Atlas ModalPopupExtender from JavaScript
Paul Hayman (44847 views)
Launching an Atlas ModalPopupExtender from JavaScript
{Looking for an '''Ajax version''' of this article??}http://www.geekzilla.co.uk/View38736C2B-BAD3-418A-A5B0-DAC4F1A5A83A.htm
Looking round the web there are some crazy ways people are trying to launch the ModalPopupExtender from JavaScrip
|
 |
Using Regular Expressions to validate a filename in a FileUpload control
Paul Hayman (39193 views)
Using Regular Expressions to validate a filename in a FileUpload control
Here's a little code snippet I use to ensure that the file that has been uploaded is of type JPG, JPEG, PNG or GIF
#c#// check anything has been uploaded
#c#if (ThumbnailImageUpload.PostedFile.ContentLength > 0)
#c#{
|
 |
Launching an Ajax ModalPopupExtender from JavaScript
Paul Hayman (36690 views)
Launching an Ajax ModalPopupExtender from JavaScript
This is an updated version of the earlier (and very popular) {Atlas article}http://www.geekzilla.co.uk/ViewDAAE6AAB-0369-45C2-BE78-B8E6F876B4F4.htm
It is by far the simplest way to launch an Ajax ModalPopupExtender from javascript.
The
|
 |
Backup ALL your SQL Server 2005 databases using ONE script
Paul Hayman (36446 views)
Backup ALL your SQL Server 2005 databases using ONE script
I wanted to backup all my databases... I had loads, creating a step for each db was getting tedious, so I wrote this script.
Enjoy
#s#DECLARE @DBName varchar(255)
#s#
#s#DECLARE @DATABASES_Fetch int
#s#
#s#DECLARE DATABASES_
|
 |
IP Address regular expression
Paul Hayman (33572 views)
IP Address regular expression
#c#string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
#c#
|
 |
Calling a static "page method" from Javascript using MS AJAX
Paul Hayman (32411 views)
Calling a static "page method" from Javascript using MS AJAX
Atlas gave us the ability to easily call Web Services from JavaScript. MS AJAX has gone one step further We can now call methods in the codebehine of the current page from Javascript. Here's how:
'''This is designed for v1.0.61025
|
 |
IsGuid() (Regular Expression Guid Match)
Paul Hayman (31398 views)
IsGuid() (Regular Expression Guid Match)
A regular expression for validating a string as being a Guid is..
#c#@"^(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$"
#c#
Example usage
Below is a function I try to keep handy which tests
|
 |
Google Applicance - googleoff / googleon Tags
Paul Hayman (25781 views)
Google Applicance - googleoff / googleon Tags
'''I came across these recently... thought I'd share''' ;)
The googleoff/googleon tags disable the indexing of a part of a web page. The result is that those pages do not appear in search results when users search for the tagged word or phrase. F
|
 |
A simple guide to creating your first Vista Gadget
Paul Hayman (25047 views)
A simple guide to creating your first Vista Gadget
Gadgets are simply HTML and JavaScript. The SideBar exposes a bunch of API's which are accessible from JavaScript and extends the HTML schema. In this short guide we will greate a simple "Hello World" gadget.
The four steps
*Create a dir
|
 |
Enabling Service Broker
Paul Hayman (21840 views)
Enabling Service Broker
The following T-Sql enables or disabled service broker on SqlServer 2005. The Service Broker is required by .net for SqlCacheDependency support
#s#-- Enable Service Broker:
#s#ALTER DATABASE [Database Name] SET ENABLE_BROKER;
#s#
#s#-- Disable Service Broker:
#s#A
|
 |
Enabling TRUSTWORTHY on a SQL 2005 Database
Paul Hayman (15859 views)
Enabling TRUSTWORTHY on a SQL 2005 Database
If your .NET stored procedure wants to have external access, the targer database will have to have TRUSTWORTHY set on.. this is how you do it.
#c#ALTER DATABASE databasename SET TRUSTWORTHY ON;
#c#GO
|
 |
Programmatically resolving ~ URL's to the Virtual Root using ResolveURL()
Paul Hayman (15617 views)
Programmatically resolving ~ URL's to the Virtual Root using ResolveURL()
It's common knowledge that a control, when '''Runat="server"''' will resolve it's src or href attribute to a virtual root when the URL starts with '''~/'''
For example:
#h#<a href="~/Customers/Profile.aspx" Runat="serv
|
 |
Adding a transparent background to a Vista Gadget
Paul Hayman (15311 views)
Adding a transparent background to a Vista Gadget
Adding a transparent background to a gadget is easy Simply create a transparent .png file and reference it from your Gadget HTML.
Here is an example file (also attached to this article as a download):
[[background.gif]]
Here is the HTM
|
 |
Highlighting keywords in text using Regex.Replace (Perfect for SEO)
Paul Hayman (14695 views)
Highlighting keywords in text using Regex.Replace (Perfect for SEO)
Why
I needed to take some text and bold certain keywords before returning the data to the web browser to enhance my {Search Engine Optimization}http://www.kwiboo.com/Services/Search-Engine-Optimisation
Example
The f
|
 |
Writing CLR Stored Procedures in C#
Paul Hayman (13638 views)
Writing CLR Stored Procedures in C#
As SQL Server 2005 rolls out DBA's are going to be forced to learn either C# or Visual Basic or both. Until now these were client side languages and not knowing them had little impact on your job. And if you write code in these languages your going to have to
|
 |
Returning a value from a PageMethod
Paul Hayman (12712 views)
Returning a value from a PageMethod using MS AJAX
'''NOTE: This is designed for v1.0.61025.0 of AJAXExtensionsToolbox.dll'''
If you've ever returned data from a web service using MS AJAX this technique will look familar.
Call the method from javascript by append PageMethods. to the front
|
 |
Triple DES encryption wrapper
Paul Hayman (12605 views)
Triple DES encryption wrapper
Here is a handy wrapper for Triple DES encryption:
#c#using System;
#c#using System.Collections.Generic;
#c#using System.Text;
#c#using System.Security.Cryptography;
#c#using System.IO;
#c#
#c#namespace Security
#c#{
#c# /// <summary>
#c# /// Wrap
|
 |
Sorting an XML document in C# using XSL
Paul Hayman (11840 views)
Sorting an XML document in C# using XSL
I needed to sort some XML in C# before itterating through the document. In the end I used the XslCompiledTransform to apply an XSL stylesheet to the XML document. Works very quickly. For reference, this is how I did it.
The code
The following uses
|
 |
CLR Stored Procedure for searching files
Paul Hayman (11502 views)
CLR Stored Procedure for searching files
I was recently asked to write a CLR stored procedure which would process a text file and return a row for each line in the file that contained text matching our search criteria.
I'd never written a CLR stored proc before so it was an interesting learn
|
 |
Reading a file which is locked by another process
Paul Hayman (11424 views)
Reading a file which is locked by another process
The following code snippet shows how to read a file which is locked by another process..
#c#FileStream logFileStream = new FileStream("c:\test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
#c#StreamReader logFileReader = new S
|
 |
Web 2 Ajax Style Animated Gif's
Paul Hayman (11083 views)
Web 2 Ajax Style Animated Gif's
When searching high and low for a ajax style wait icon I came across the following sites.
The first is a very good source of {web 2}http://www.kwiboo.com/Glossary/Web2 style animated gifs:
http://www.sanbaldo.com/wordpress/1/ajax_gif/ - Example: [[bigrotati
|
 |
What screen size should we be building sites for?
Paul Hayman (10422 views)
What screen size should we be building sites for?
With high resolution screens becoming increasingly cheaper to buy, what screen size should we really be building websites for?
I took some stats from GeekZilla (in google analytics) and was pleased to find that the most popular was reasonable
|
 |
Could not write to output file ... The directory name is invalid
Paul Hayman (10119 views)
Could not write to output file ... The directory name is invalid
Recently had a problem deploying an app to a fresh 2003 server. Basically, the application wouldn't start, instead we recieved an error stating that the compiler couldn't write to the '''"Temporary ASP.NET Files"''' folder because
|
 |
Dynamically adding a CSS link to the page in c#
Paul Hayman (9926 views)
Dynamically adding a CSS link to the page in c#
The following code adds a CSS link to the header node of a Html page.
#c#// register css
#c#HtmlHead head = (HtmlHead)Page.Header;
#c#HtmlLink link = new HtmlLink();
#c#link.Attributes.Add("href", Page.ResolveClientUrl("~/App_Themes/Defaul
|
 |
Restricting the number of rows in a dataview when binding to a repeater
Paul Hayman (9150 views)
Restricting the number of rows in a dataview when binding to a repeater
The problem
I needed to restrict the number of items bound to an '''asp:repeater'''. Basically I never wanted more than 10 items to be displayed.
Options
The right thing to do would be to restrict the number of it
|
 |
Adding a Strong Name to an existing DLL that you don't have the source to
Paul Hayman (8377 views)
Adding a Strong Name to an existing DLL that you don't have the source to
There are times when you need a DLL to have a strong name; putting it in the GAC for example. With 3rd party DLL's this could be a pain. This is how you do it:
From a VS.NET command prompt, enter the following:
'
|
 |
Getting the Virtual Path of a Request in c#
Paul Hayman (8304 views)
Getting the Virtual Path of a Request in c#
This simple bit of code will get you the '''Virtual Path''' of your current request.
#c#public static string GetVirtualPath(string url)
#c#{
#c# if (HttpContext.Current.Request.ApplicationPath == "/")
#c# {
#c# return "~" + url;
#
|
 |
Centering a DIV using the negative margin method
Paul Hayman (7512 views)
Centering a DIV using the negative margin method
The following CSS will center a DIV whih is 500px wide. This method is very clean and works in all browsers.
#c#div {
#c# position: absolute;
#c# left: 50%;
#c# width: 500px;
#c# margin-left: -250px;
#c#}
Change the width to suit your
|
 |
DTS, Excel and mixed format columns
Paul Hayman (6758 views)
DTS, Excel and mixed format columns
I recently had a problem DTS importing an Excel spreadsheet which contained columns with mixed text and data values. After a bit of hunting around, I found an extended property IMEX=1. The IMEX=1 property forces everything to text when reading from a source.
|
 |
Hex code Regular Expression (#F0F0F0)
Paul Hayman (6747 views)
Hex code Regular Expression (#F0F0F0)
The following matches valid HTML hexadecimal color codes. The # symbol is optional. It will except either the 3 digit form for the 216 Web safe colors, or the full 6 digit form.
#c#^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$
|
 |
Regex match html content without screwing up the tags
Paul Hayman (6663 views)
Regex match html content without screwing up the tags
When needing to highlight words in a string containing HTML we found we soon ran into problems when the word we were searching for appeared in the middle of a tag..
Imagine the example:
#v#<a href="geekzilla.aspx">you searched for geek
|
 |
Using Regex Look Arounds
Paul Hayman (6613 views)
Using Regex Look Arounds
.net supports four types of "Look Around". These can be used to make sure that patterns do or do not appear before or after whatever it is you're matching on. Consider the following text:
#c#"my car will be off the road for 2 days. it's reg num is ab123abc"
If I w
|
 |
ISBN Number regular expression
Paul Hayman (6579 views)
ISBN Number regular expression
#c#string pattern = @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$";
Examples
#c#// Valid
#c#Console.WriteLine(Regex.IsMatch(@"ISBN 0 93028 923 4", @"ISBN\x20(?=.{13}$)\d{1,5}([- ])\d{1,7}\1\d{1,6}\1(\d|X)$"));
#c#
#c#// Valid
#c#Console.Wr
|
 |
Using Regex.Replace
Paul Hayman (6482 views)
Using Regex.Replace
Say you want to get the username from a fully qualified username such as '''MyDomain\AUser'''
Most developers would turn to SubString and LastIndexOf functions .. for example
#c#string userName = @"MyDomain\AUser";
#c#string result = userName.SubString(userName.LastInde
|
 |
Geting the position of the mouse pointer (cursor) in JavaScript (Works in IE7)
Paul Hayman (6480 views)
Geting the position of the mouse pointer in JavaScript (Works in IE7)
The following function will return the position of the mouse pointer based on the event. It actually works in IE7.
#c#function getPosition(e) {
#c# e = e || window.event;
#c# var cursor = {x:0, y:0};
#c# if (e.
|
 |
Date Regular Expression (dd/MMM/yyyy)
Paul Hayman (6260 views)
Date Regular Expression (dd/MMM/yyyy)
The following matches:
*01/JAN/2007
*22/Feb/2006
But doesn't match:
*01/01/2007
*22/02/2007
*01 Jan 2007
#c#^(([0-9])|([0-2][0-9])|([3][0-1]))\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4}$
|
 |
Using a DataSet as a return type on an Atlas Javascript WebService call
Paul Hayman (5959 views)
Using a DataSet as a return type on an Atlas Javascript WebService call
If the WebService you are calling returns a DataSet it may not be obvious how to get to the data in the returned object.
Here is a little example which may help you on your way..
#h#<script language="javascript">
#
|
 |
Handy Keyboard Shortcuts for c# 2005
Paul Hayman (5738 views)
Handy Keyboard Shortcuts for c# 2005
The following keyboard shortcuts I find invaluable. It's amazing how many people still use the mouse to do everything.
Document navigation
||Ctrl+Tab|| Switch documents||
||Ctrl+Shift+Tab|| Reverse switch documents||
||Ctrl+kk|| Drop a bookmark||
||
|
 |
Installing XNA Beta
Paul Hayman (5450 views)
Installing XNA Beta
Ok, I thought I'd document the installation process and any pitfalls I encountered. I decided to install XNA on a VMWare machine, just to keep things clean, '''this didn't work''' as XNA couldn't detect an appropriate Direct3d compatible graphics card, so I installed it on t
|
 |
Fixing broken users after Database Restore
Paul Hayman (5278 views)
Fixing broken users after Database Restore
Ever restored a Database which was created on a different server then not been able to use the same logon you had previously set up?
This command fixes the problem with the account.
#s#-- Replace username with the account to fix
#s#sp_change_users
|
 |
How to get more than 3GB in Windows Vista 32-bit
Paul Hayman (5277 views)
How to get more than 3GB in Windows Vista 32-bit
Out if the box, Vista (32-bit) only detects a maximum of 3GB of RAM. You're probably gutted if you just bought a 4GB PC.
Vista 32-bit systems can actually detect 4GB RAM (and more). Sometimes the O.S. does not see the 4th GB of RAM but that c
|
 |
class.Serialize()
Paul Hayman (5266 views)
class.Serialize()
Handly little function which I include in most classes. This function returns the object serialized as XML, perfect for logging etc.
#c#/// <summary>
#c#/// Serialize this object
#c#/// </summary>
#c#/// <returns>XmlDocument containing the current information serialized<
|
 |
Custom Templated SiteMap Navigator Control
Paul Hayman (5155 views)
Custom Templated SiteMap Navigator Control
After discovering the power of the SiteMap, especially when linked to Authentication, it wasn't long before binding the TreeView to the map was not enough.
I needed to have total control over what was displayed to the user for each item, so I wrote
|
 |
How to turn on automatic logon in Windows XP
Paul Hayman (5043 views)
How to turn on automatic logon in Windows XP
Original : http://support.microsoft.com/kb/315231
INTRODUCTION
This article describes how to configure Microsoft Windows XP to automate the logon process by storing your password and other pertinent information in the registry database. This fe
|
 |
Programmatically registering a client script in the ScriptManager
Paul Hayman (5020 views)
Programmatically registering a client script in the ScriptManager
Registering a client script in the ScriptManager is easy
#c#ScriptManager.RegisterClientScriptInclude(Page, typeof(Page),
#c# "MyScript",
#c# Page.ResolveClientUrl("~/scripts/SomeJavascript.js"));
#c#
|
 |
Programmatically adding LINKs to HTML HEADER in Code Behind
Paul Hayman (4985 views)
Programmatically adding LINKs to HTML HEADER in Code Behind
In this example I am adding a link to the html header pointing to an rss feed.
#c#HtmlLink link = new HtmlLink();
#c#link.Attributes.Add("type", "application/rss+xml");
#c#link.Attributes.Add("rel", "alternate");
#c#link.Attribut
|
 |
Calling a WebService (from JavaScript) with Atlas
Paul Hayman (4930 views)
Calling a WebService (from JavaScript) with Atlas
This is too easy and damn powerful WebServices can be called from JavaScript directly once the service is registered in the Script Manager.
Script Manager
Add your service to the manager as seen below:
#h#<atlas:ScriptManager runat="serv
|
 |
ASP.NET Framework 1.1 Validation not working in IE7?
Paul Hayman (4735 views)
ASP.NET Framework 1.1 Validation not working in IE7?
I recently had a problem with an old '''Framework 1.1''' website where the form would not post back if the page contained validators (CustomValidators to be exact). It caused me to do a lot of googling and in the end some javascript debugging
|
 |
Remembering position of DragOverlayExtender with Profile
Paul Hayman (4664 views)
Remembering position of DragOverlayExtender with Profile
You can get Atlas to store the last known position of your floating panel in the profile.
Three things you need to do to get this to work.
ProfileScriptService
In the page with the DragOverlayExtender you'll need to add a atlas
|
 |
Fixing Actionscript XML newline problem
Paul Hayman (4493 views)
Fixing Actionscript XML newline problem
I was having a nightmare with a newline '''\n''' coming through from an XML document literally as \n when I passed the text into a DynamicText object in ActionScript 2, Flash CS3.
Mark Page found this solution:
#c#function fixXMLNewLines(str:String)
|
 |
LoginStatus not logging users out?
Paul Hayman (4448 views)
LoginStatus not logging users out?
Have you noticed your '''LoginStatus''' control doesn't log the user out when you click '''Logout'''? Well, to fix this all you need to do is add an '''id''' attribute.
This works
#h#<asp:LoginStatus runat="server" id="loginstatus1" />
This doesn
|
 |
Setting default collation on a column
Paul Hayman (4385 views)
Setting default collation on a column
The following will set the collation on a column in a table back to Database Default without dropping and recreating the table (unlike Enterprise Manager)
#s#ALTER TABLE [MyTable] ALTER COLUMN [MyColumn]
#s# varchar(50) COLLATE database_def
|
 |
Why not on by defaut? Turn on auto HTML attribute quotes in 2005
Paul Hayman (4101 views)
Why not on by defaut? Turn on auto HTML attribute quotes in 2005
Holy cow Why wasn't this on by default??? How annoying is it that when typing in the HTML Source editor window Visual Studio doesn't add the "" for you automatically?? If it's going to complain profusely about the missing quotes
|
 |
Firefox doesn't use parentElement, it uses parentNode
Paul Hayman (4055 views)
Firefox doesn't use parentElement, it uses parentNode
JavaScript in FireFox doesn't support the function parentElement. You should use parentNode instead.
Example:
#h#myElement.parentNode;
|
 |
Evaluating Expressions
Paul Hayman (3821 views)
Evaluating Expressions
You can evaluate sums in the fly using .net DataTables.
This is how you do it (C# 2005).
#c#string sum = "(1+2)/4";
#c#System.Data.DataTable evaluator = new System.Data.DataTable("temp");
#c#double result;
#c#
#c#result = (double)evaluator.Compute(sum, null);
|
 |
Custom JavaScript attributes work differently in IE compared to Firefox
Paul Hayman (3572 views)
Custom JavaScript attributes work differently in IE compared to Firefox
Adding custom attributes to HTML tags is a really valuable programming method. It's something I do quite often.
Consider the following code:
#h#<script>
#h# function DoSomething(el){
#h# alert(el.contentId);
#h# }
|
 |
Awesome Sidebar Gadget
Paul Hayman (3544 views)
Awesome Sidebar Gadget
This gadget is awesome '''(ESPECIALLY IN LARGE MODE)''':
http://gallery.live.com/liveItemDetail.aspx?li=426dc418-12ce-481a-b886-89a66ca9127e
System Control is much more than your average shutdown gadget. Aside from the normal Shutdown, Restart, Lock, and Sleep /
|
 |
The easiest Hex string to/from byte array I've found
Paul Hayman (3486 views)
The easiest Hex string to/from byte array I've found
When looking for a utility function to convert from a hex string to a byte array, I found this example .. works a treat
http://programmerramblings.blogspot.com/2008/03/convert-hex-string-to-byte-array-and.html
Code
#c#/// <SUMM
|
 |
Stopping simultaneous logins (Forms Authentication)
Paul Hayman (3469 views)
Stopping simultaneous logins (Forms Authentication)
The following code (called from a page load) will bump off users who are logged in when someone else logs in with the same credentials.
#c#public bool ValidSession()
#c#{
#c#
#c# lock (Cache)
#c# {
#c#
#c# string requestU
|
 |
Email Address Regular Expression
Paul Hayman (3462 views)
Email Address Regular Expression
#c#string pattern = @"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"
#c#
|
 |
Credit Card Number Ranges
Paul Hayman (3415 views)
Credit Card Number Ranges
Here is the basic set of credit card number ranges:
||'''Issuer'''|| '''Identifier'''|| '''Card Number Length''' ||
||Diner's Club/Carte Blanche|| 300xxx-305xxx, 36xxxx, 38xxxx|| 14 ||
||American Express ||34xxxx, 37xxxx ||15 ||
||VISA|| 4xxxxx ||13, 16 ||
||Mas
|
 |
Linking from one CSS StyleSheet to Another
Paul Hayman (3335 views)
Linking from one CSS StyleSheet to Another
Simply add the following to the top of your CSS StyleSheet to link it to another:
#c#@import "MyOtherStylesheet.css";
'''NOTE:''' the path is relative to the current StyleSheet
|
 |
The null coalescing operator: ??
Paul Hayman (3305 views)
The null coalescing operator: ??
This is a new feature of c# 2.0. The null coalescing operator is a short cut for checking if a value is null and if so returning the value of the second operand. Kind of like an IIF. The syntax is as follows:
#c#string newValue = someValue ?? "default";
|
 |
Changing the password rules for Forms Authentication
Paul Hayman (3276 views)
Changing the password rules for Forms Authentication
An annoying feature of the forms authentication controls shipped with VS2005 is that it forces users to enter non-alphanumberic characters in their passwords by default.. e.g. password would have to be password
Fortunately, this option ca
|
 |
The best CSS rounded corners method
Paul Hayman (3211 views)
The best CSS rounded corners method
I love this example :
{Even More CSS Roudned Corners 2}http://www.schillmania.com/projects/dialog2/
{Project Home}http://www.schillmania.com/content/projects/even-more-rounded-corners/
{Basic Example}http://www.schillmania.com/projects/dialog2/basic.html
|
 |
Rendering a Control to a String
Paul Hayman (3201 views)
Rendering a Control to a String
This is a really handy little function for rendering a control to a string. Really handy if you want to pass back rendered HTML from a StaticPageMethod or WebService.
#c#private static string GetRenderedControl(Control control)
#c#{
#c# HtmlTextWriter wri
|
 |
Converting a String to a ByteArray in c#
Paul Hayman (3137 views)
Converting a String to a Byte Array in c#
Very simple.. here's how to convert a String to a Byte Array in c#
#c#byte[] yourByteArray = Encoding.ASCII.GetBytes("your string");
|
 |
Handy fake latin generator
Paul Hayman (3069 views)
Handy fake latin generator
4guysfromrolla have a handy "fake latin" generator. It allows you to specify the number of paragraphs to generate. Source available too, although old asp.
http://www.4guysfromrolla.com/demos/latin.asp?paras=2
|
 |
Using named match groups in expressions
Paul Hayman (3065 views)
Using named match groups in expressions
The following code will return the value '''user'''
#c#Console.WriteLine(Regex.Match(@"test\user", @".*\\(.*?)$").Groups[1]);
Sometimes it makes life easier to refer to the group by name rather than its position (or GroupNum). To do this we need to
|
 |
Enabling CLR execution in SQL Server
Paul Hayman (3055 views)
Enabling CLR execution in SQL Server
If you plan to run stored procedures you have written in .NET you will probably need to enable CLR execution on your server.
To do this you'll need to run the following T-SQL
#c#sp_configure 'clr enabled', 1
#c#GO
#c#RECONFIGURE
#c#GO
|
 |
Specifying an originator IP Address on a WebService Request using ServicePoint and HttpWebRequest
Paul Hayman (3045 views)
Specifying an originator IP Address on a WebService Request using ServicePoint and HttpWebRequest
If you're running multiple IP Addresses on the same NIC in Windows 2003 server and you need a webservice call to originate from a certain one, you'll probably have found the same thing I did. .net
|
 |
Email Regex Pattern
Paul Hayman (2937 views)
Email Regex Pattern
#c#^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
|
 |
Intellisence not working in web.config?
Paul Hayman (2823 views)
Intellisence not working in web.config?
Visual Studio 2005 has an interesting "feature" where Intellisence will not pop up when you're editing a web.config file. Annoying eh? Well, I found that removing the '''namespace''' from the '''configuration''' tag kicks it all back into life.
Change
|
 |
Assigning an array of strings to a variable
Paul Hayman (2820 views)
Assigning an array of strings to a variable
Declaring a string array with hard coded data is easy.
#c#string[] newString = new string[] {"one", "two", "three"}
Passing hard coded array into method
Likewise, passing an array of hard coded data into a method is also easy..
For example
|
 |
Fixing Form Action on UrlRewrite (UrlRewriter)
Paul Hayman (2772 views)
Fixing Form Action on UrlRewrite
IF you're rewriting URL's, you've probably come across the same problem I had.
When posting back on the page, the real URL is used.. this is a real pain if you're writing a page which uses the '''RawUrl''' to serve up relevant content.
I had a good look a
|
 |
Code snippet for 'protected void MethodName(object sender, EventArgs e)' method
Paul Hayman (2712 views)
Code snippet for 'protected void MethodName(object sender, EventArgs e)' method
When adding a method to handle server events (such as OnClick) I often found myself copying the Page_Load method and changing the name. I looked for a snippet which would create this method for me but had no luck, s
|
 |
Time Regular Expression
Paul Hayman (2649 views)
Time Regular Expression
#c#^([0-1][0-9]|[2][0-3]):([0-5][0-9])$
|
 |
Displaying XML just like Internet Explorer
Paul Hayman (2605 views)
Displaying XML just like Internet Explorer
This is everything you need to display XML in your webpage the same way IE displays it when you open an XML document in IE.
Html
Register the js and place a literal where you'd like the XML to appear.
#h#<script src="XMLControl.js" type="tex
|
 |
Error in Line 3?
Paul Hayman (2590 views)
Error in line 3
Some websites report an error in line 3 when using the asp.net controls such as login. We recently tracked this error down on one of our sites to the use of custom HttpHandlers.
All requests to anything other than *.aspx were routing through our own handler..
Adding the fo
|
 |
Microsoft XNA (Beta) Released
Paul Hayman (2504 views)
Microsoft XNA (Beta) Released
#$#<a href="http://www.dotnetkicks.com/kick/?url=http://www.geekzilla.co.uk/View7ABBD0E1-3FA6-4BCA-A5F0-AB5A16AE2ADF.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.geekzilla.co.uk/View7ABBD0E1-3FA6-4BCA-A5F0-AB5A1
|
 |
Convert to and from Hex
Paul Hayman (2256 views)
Convert to and from Hex
Convert from an int to Hex
#c#String result = String.Format("{0:x2}", 255)
Convert from Hex to an int
#c#int result = int.Parse("FF", System.Globalization.NumberStyles.HexNumber);
|
 |
Getting the ProviderUserKey for the Current User
Paul Hayman (2239 views)
Getting the ProviderUserKey for the Current User
The following gets the ProviderUserKey for the current user.
#c#(Guid)Membership.GetUser().ProviderUserKey
|
 |
Mail and News Regular Expression
Paul Hayman (2228 views)
Mail and News Regular Expression
#c#string pattern = @"(?<ignore>(^|\s|\W)[\W*])?(?<uri>((mailto|news){1}:[^(//\s,)][\w\d:#@%/;$()~_?\+-=\\\.&]+))"
#c#
|
 |
Generating a resized image with maximum image quality
Paul Hayman (2193 views)
Generating a resized image with maximum image quality
Here's some code I use for generating a resized image with no Jpeg compression.
#c#public MemoryStream GetResized(Bitmap originalImage, int width, int height)
#c#{
#c# System.Drawing.Image outputImage;
#c# MemoryStream outputStre
|
 |
Cleaning a string using a regular expression ready for placing in a URL
Paul Hayman (2190 views)
Cleaning a string using a regular expression ready for placing in a URL
#c#public static string CleanForUrl(string text)
#c#{
#c# return Regex.Replace(text, @"[^a-z^A-Z^0-9^-]", "-");
#c#}
|
 |
Adding a Favicon to your site
Paul Hayman (2120 views)
Adding a FavIcon to your site
Found a handy little site which allows you to upload a GIF or Jpeg and returns you a static and animated FavIcon with all the HTML you need to implement.
http://www.chami.com/html-kit/services/favicon/
|
 |
Reading a key from the registry in c#
Paul Hayman (2101 views)
Reading a key from the registry in c#
The following c# code shows how to read a key value from the registry.
#c#Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
#c#RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\yourapp\\yourkey");
#c#string value = "";
#c#if (mas
|
 |
Regex for a HTML tag
Paul Hayman (2049 views)
Regex for a HTML tag
#c#<.[^>]*>
This can proove invaluable when you're wanting to replace keywords in HTML without spoiling the tags themselves. Particularly useful in SEO.
|
 |
Scrollbar CSS style generator
Paul Hayman (2047 views)
Scrollbar CSS style generator
Excellent online tool for generating css for scrollbars
http://iconico.com/CSSScrollbar/
|
 |
Returning a Distinct list of values from an array or IEnumerable cllection
Paul Hayman (2041 views)
Returning a Distinct list of values from an array or IEnumerable collection
I recently had a list of Guids in a string which was returned from a group of checkboxes with identical names. I wanted to itterate through Guids and process each one only once. Basicaly, ignoring duplicates.
I didn'
|
 |
Using a .Net 2.0 anonymous delegate when generating a thumbnail
Paul Hayman (2033 views)
Using a .Net 2.0 anonymous delegate when generating a thumbnail
Rather than using a mehod which does nothing except return false. Use a .Net 2.0 anonymous delegate for the GetThumbnailImageAbort parameter.
#c#delegate() { return false; }
Example
#c#System.Drawing.Image thumbResult = t
|
 |
Get the Top and Left location of an element with JavaScript
Paul Hayman (2011 views)
The following code will return the top and left position for an element.
#c#var ns4 = (navigator.appName.indexOf("Netscape")>=0
#c# && parseFloat(navigator.appVersion) >= 4
#c# && parseFloat(navigator.appVersion) < 5)? true : false;
#c#var ns6 = (parseFloat(navigator.app
|
 |
What is a FavIcon
Paul Hayman (2009 views)
What is a FavIcon
FavIcon (short for Favorites Icon) is a feature that makes it possible to associate a special logo or other small graphic with a web page.
The favicon is usually displayed next to the web site address. Much like the way shortcut icons are used on the computer desktop to di
|
 |
No more cellspacing, roll on border-collapse!
Paul Hayman (1921 views)
No more cellspacing, roll on border-collapse
Confused as to why applying a css '''margin:0px''' and '''padding:0px''' doesn't remove the gaps between cells in tables? You need border-collapse.
The cellpadding and cellspacing attributes are not deprecated in HTML 4 (and not even in XHTML 1.1
|
 |
Preventing Caching of an ASP.net page in c#
Paul Hayman (1837 views)
Preventing Caching of an ASP.net page in c#
The following code prevents a page being cached.
#c#public static void PreventCaching(HttpContext context)
#c#{
#c# context.Response.Cache.SetExpires(DateTime.Now.Subtract(new TimeSpan(24, 0, 0)));
#c# context.Response.Cache.SetCacheabil
|
 |
Returning the first few items from an Array list or IEnumerable collection
Paul Hayman (1787 views)
Returning the first few items from an Array list or IEnumerable collection, like T-Sql top()
I needed to bind the first 5 items in a List<T> to a repeater. Having recently discovered the .Distinct() extension, I had a look through the other methods attached to my List<T> and found .Take(int)
|
 |
GeekZilla Google Analytics Report August 07
Paul Hayman (1784 views)
GeekZilla Google Analytics Report August 07
[[geekzila_august.gif]]
|
 |
By Invitation Only
Paul Hayman (1772 views)
By Invitation Only
The GeekZilla community has been opened up '''by invitation only'''
The team and their friends have all been issued 5 invitations each to send out to their buddies.
The site is still in state of beta, it will be interesting to see how this wider group of developers and
|
 |
Comments now use Wiki text
Paul Hayman (1679 views)
Comments now use Wiki text
Comments added to articles now use wiki text.. this means you can paste code, include hyperlinks, use smileys.
To paste code : add #c# infront of each line for C#, #h# for html, #v# for vb.net or #s# for T-SQL
|
 |
Great site for Vista WallPaper and more!
Paul Hayman (1656 views)
Great site for Vista WallPaper and More
http://neosmart.net/gallery/v/wallpapers/Vista/official/
|
 |
Non Capturing Groups
Paul Hayman (1638 views)
Non Capturing Groups
Expressions can contain a lot of groups which you weren't interested in matching on. It is possible to tell .net not to capture these by placing a '''?:''' at the beginning of the group. Apparently limiting the number of capturing groups has a '''positive increase on perfor
|
 |
GeekZilla Google Analytics Report July 07
Paul Hayman (1629 views)
GeekZilla Google Analytics Report July 07
[[last30days.gif]]
|
 |
StringOrDBNull method
Paul Hayman (1579 views)
StringOrDBNull
This method accepts a string and returns DBNull.Value if the string is null or empty.
#c#public static object StringOrDBNull(string value)
#c#{
#c# try
#c# {
#c# if ((value == null) || (value == String.Empty))
#c# {
#c# return DBNull.Value;
|
 |
geekzilla preparing for a facelift
Paul Hayman (1416 views)
geekzilla preparing for a facelift
We're getting ready to facelift geekzilla using {kwiboo's}http://www.kwiboo.com {Wiki Content Management System}http://www.kwiboo.com/Products/Content-Management as the foundation, making it more powerful, scalable, easier to use and more pleasing to the eye.
|
 |
Excellent IIS Metabase Helper
Paul Hayman (1299 views)
Excellent IIS Metabase Helper
Found this : http://agramont.net/blogs/provware/default.aspx
http://agramont.net/blogs/provware/archive/2006/07/31/Provware_3A00_-Getting-Started-_2800_Build-001_2900_.aspx
Has the potential to be an excellent Metabase wrapper.
|
 |
AS2 removeMovieClip not unloading my movie
Paul Hayman (1234 views)
AS2 removeMovieClip not unloading my movie
I recently had a problem where removeMovieClip would remove everything I asked it to except for a couple of movies.
Eventually, I tracked it down to a problem with the ID I had given the movie. '''It seems that movie ID's with full stops in cause pr
|
 |
Browser version detection in Javascript
Paul Hayman (1188 views)
Browser version detection in Javascript
#c#var ns4 = (navigator.appName.indexOf("Netscape")>=0 &&
#c# parseFloat(navigator.appVersion) >= 4 &&
#c# parseFloat(navigator.appVersion) < 5)? true : false;
#c#
#c#var ns6 = (parseFloat(navigator.appVersion) >= 5 &&
#c# naviga
|
 |
Visual Studio Orcas Beta 1 Available
Paul Hayman (1155 views)
Visual Studio Orcas Beta 1 Available
You can now download Visual Studio Orcas Beta 1. Use one of the links found here:
* {The Team Suite Edition on a Virtual PC}http://www.microsoft.com/downloads/details.aspx?FamilyId=36B6609E-6F3D-40F4-8C7D-AD111679D8DC&displaylang=en
* {Team Suite on
|
 |
Instanciating an object from it's type name
Paul Hayman (1148 views)
Instanciating an object from it's type name
Instanciating a control from it's type name is easy..
#c#string typeName = "YourNameSpace.YourObject";
#c#
#c#Type assType = Type.GetType(typeName);
#c#object dynamicControl = Activator.CreateInstance(assType);
One thing you may run into is t
|
 |
Stopping Focus Highlight on a mx.controls.TextInput in ActionScript on TAB
Paul Hayman (999 views)
Stopping Focus Highlight on a mx.controls.TextInput in Action Script on TAB
I recently had a problem with a mx.controls.TextInput which rendered a highlignt area below the TextInput when I tabbed into the control.
After much hunting around, I found the following Action Script solution:
|
 |
Introducing Microsoft Silverlight
Paul Hayman (995 views)
Introducing Microsoft Silverlight
Ref : http://blogs.msdn.com/tims/archive/2007/04/15/introducing-microsoft-silverlight.aspx
It is with tremendous pleasure that I can reveal Microsoft Silverlight: our next-generation, cross-platform, cross-browser web client runtime. Silverlight (previously
|
 |
FTP series codes
Paul Hayman (577 views)
FTP series codes
||*Code* ||*Description*||
||100 || The requested action is being initiated, expect another reply before proceeding with a new command. ||
||110 || Restart marker reply. ||
||120 || Service ready in nnn minutes. ||
||125 || Data connection already open, transfer starting.
|
 |
Select a list of databases missing Primary keys
Paul Hayman (340 views)
Select a list of databases missing Primary keys
The following T-SQL returns a list of tables in a database which have no primary key set.
#s# select * from sys.tables where object_id not in (
#s# select object_id from sys.indexes where is_primary_key = 1
#s# )
#s# order by name
|
 |
GeekZilla Google Analytics Report July 2010
Paul Hayman (50 views)
GeekZilla Google Analytics Report July 2010
[[geekzila_july_2010.gif]]
|
 |
Output Exchange Message Tracking Log to CSV or Excel
Paul Hayman (44 views)
Output Exchange Message Tracking Log to CSV or Excel
#c#get-messagetrackinglog -Start "07/09/2010 00:00:00" -End "07/09/2010 23:59:00"
#c#-resultSize unlimited | select timestamp, sender, {$_.recipients}, messagesubject,
#c#internalmessageid, clientid, clienthostname, serverip, serverhostna
|
 |
DateTime.ToString() Patterns
Paul Hayman (42 views)
DateTime.ToString() Patterns
All the patterns:
||0|| MM/dd/yyyy|| 08/22/2006 ||
||1|| dddd, dd MMMM yyyy|| Tuesday, 22 August 2006 ||
||2|| dddd, dd MMMM yyyy|| HH:mm Tuesday, 22 August 2006 06:30 ||
||3|| dddd, dd MMMM yyyy|| hh:mm tt Tuesday, 22 August 2006 06:30 AM ||
||4|| dddd, dd
|
 |
DateTime.ToString() Patterns
Paul Hayman (32 views)
DateTime.ToString() Patterns
All the patterns:
||0|| MM/dd/yyyy|| 08/22/2006 ||
||1|| dddd, dd MMMM yyyy|| Tuesday, 22 August 2006 ||
||2|| dddd, dd MMMM yyyy|| HH:mm Tuesday, 22 August 2006 06:30 ||
||3|| dddd, dd MMMM yyyy|| hh:mm tt Tuesday, 22 August 2006 06:30 AM ||
||4|| dddd, dd
|