 |
DateTime.ToString() Patterns
Paul Hayman (898195 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 (124682 views)
URL Regular Expression
#c#string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"
#c#
|
 |
Backup ALL your SQL Server 2005 databases using ONE script
Paul Hayman (64094 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_
|
 |
Calling a static "page method" from Javascript using MS AJAX
Paul Hayman (63863 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
|
 |
Launching an Ajax ModalPopupExtender from JavaScript
Paul Hayman (61174 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
|
 |
Creating a Tag Cloud in C#
Paul Hayman (59277 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
|
 |
Using Regular Expressions to validate a filename in a FileUpload control
Paul Hayman (57683 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#{
|
 |
IP Address regular expression
Paul Hayman (53964 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#
|
 |
Launching an Atlas ModalPopupExtender from JavaScript
Paul Hayman (51301 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
|
 |
IsGuid() (Regular Expression Guid Match)
Paul Hayman (47726 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
|
 |
Enabling Service Broker
Paul Hayman (40659 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
|
 |
Google Applicance - googleoff / googleon Tags
Paul Hayman (36688 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 (29802 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
|
 |
Programmatically resolving ~ URL's to the Virtual Root using ResolveURL()
Paul Hayman (24386 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
|
 |
Returning a value from a PageMethod
Paul Hayman (22868 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
|
 |
Enabling TRUSTWORTHY on a SQL 2005 Database
Paul Hayman (22015 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
|
 |
Adding a transparent background to a Vista Gadget
Paul Hayman (20232 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
|
 |
Dynamically adding a CSS link to the page in c#
Paul Hayman (18999 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
|
 |
Reading a file which is locked by another process
Paul Hayman (18169 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
|
 |
Highlighting keywords in text using Regex.Replace (Perfect for SEO)
Paul Hayman (17479 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
|
 |
Triple DES encryption wrapper
Paul Hayman (16856 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
|
 |
Adding a Strong Name to an existing DLL that you don't have the source to
Paul Hayman (16740 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:
'
|
 |
Sorting an XML document in C# using XSL
Paul Hayman (15779 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
|
 |
Web 2 Ajax Style Animated Gif's
Paul Hayman (15350 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
|
 |
Writing CLR Stored Procedures in C#
Paul Hayman (15211 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
|
 |
CLR Stored Procedure for searching files
Paul Hayman (13822 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
|
 |
Getting the Virtual Path of a Request in c#
Paul Hayman (13159 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;
#
|
 |
Could not write to output file ... The directory name is invalid
Paul Hayman (12707 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
|
 |
Date Regular Expression (dd/MMM/yyyy)
Paul Hayman (11905 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}$
|
 |
Hex code Regular Expression (#F0F0F0)
Paul Hayman (11884 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})?$
|
 |
Geting the position of the mouse pointer (cursor) in JavaScript (Works in IE7)
Paul Hayman (11869 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.
|
 |
What screen size should we be building sites for?
Paul Hayman (11571 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
|
 |
Restricting the number of rows in a dataview when binding to a repeater
Paul Hayman (11110 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
|
 |
Using Regex Look Arounds
Paul Hayman (10653 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
|
 |
Centering a DIV using the negative margin method
Paul Hayman (10283 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
|
 |
Using Regex.Replace
Paul Hayman (9214 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
|
 |
ISBN Number regular expression
Paul Hayman (9117 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
|
 |
Regex match html content without screwing up the tags
Paul Hayman (9085 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
|
 |
DTS, Excel and mixed format columns
Paul Hayman (8043 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.
|
 |
The easiest Hex string to/from byte array I've found
Paul Hayman (7551 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
|
 |
Firefox doesn't use parentElement, it uses parentNode
Paul Hayman (7282 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;
|
 |
Using a DataSet as a return type on an Atlas Javascript WebService call
Paul Hayman (7066 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 (6929 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||
||
|
 |
Fixing broken users after Database Restore
Paul Hayman (6784 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
|
 |
Setting default collation on a column
Paul Hayman (6731 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
|
 |
class.Serialize()
Paul Hayman (6602 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<
|
 |
Programmatically registering a client script in the ScriptManager
Paul Hayman (6573 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 (6183 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
|
 |
How to get more than 3GB in Windows Vista 32-bit
Paul Hayman (6075 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
|
 |
Installing XNA Beta
Paul Hayman (6009 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 Actionscript XML newline problem
Paul Hayman (5821 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 (5772 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
|
 |
Custom Templated SiteMap Navigator Control
Paul Hayman (5720 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 (5704 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
|
 |
Custom JavaScript attributes work differently in IE compared to Firefox
Paul Hayman (5693 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# }
|
 |
ASP.NET Framework 1.1 Validation not working in IE7?
Paul Hayman (5576 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
|
 |
Calling a WebService (from JavaScript) with Atlas
Paul Hayman (5477 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
|
 |
Remembering position of DragOverlayExtender with Profile
Paul Hayman (5217 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
|
 |
Why not on by defaut? Turn on auto HTML attribute quotes in 2005
Paul Hayman (4852 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
|
 |
Credit Card Number Ranges
Paul Hayman (4736 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
|
 |
Evaluating Expressions
Paul Hayman (4630 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);
|
 |
Fixing Form Action on UrlRewrite (UrlRewriter)
Paul Hayman (4616 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
|
 |
Linking from one CSS StyleSheet to Another
Paul Hayman (4527 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
|
 |
Displaying XML just like Internet Explorer
Paul Hayman (4512 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
|
 |
Email Regex Pattern
Paul Hayman (4444 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})$
|
 |
Awesome Sidebar Gadget
Paul Hayman (4415 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 /
|
 |
Stopping simultaneous logins (Forms Authentication)
Paul Hayman (4334 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
|
 |
The best CSS rounded corners method
Paul Hayman (4273 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 (4220 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
|
 |
Time Regular Expression
Paul Hayman (4179 views)
Time Regular Expression
#c#^([0-1][0-9]|[2][0-3]):([0-5][0-9])$
|
 |
Converting a String to a ByteArray in c#
Paul Hayman (4140 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");
|
 |
Get the Top and Left location of an element with JavaScript
Paul Hayman (4131 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
|
 |
Specifying an originator IP Address on a WebService Request using ServicePoint and HttpWebRequest
Paul Hayman (4129 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
|
 |
Handy fake latin generator
Paul Hayman (4125 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
|
 |
Changing the password rules for Forms Authentication
Paul Hayman (4125 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 null coalescing operator: ??
Paul Hayman (3997 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";
|
 |
Enabling CLR execution in SQL Server
Paul Hayman (3965 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
|
 |
Email Address Regular Expression
Paul Hayman (3961 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#
|
 |
Using named match groups in expressions
Paul Hayman (3850 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
|
 |
Code snippet for 'protected void MethodName(object sender, EventArgs e)' method
Paul Hayman (3563 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
|
 |
Assigning an array of strings to a variable
Paul Hayman (3507 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
|
 |
Error in Line 3?
Paul Hayman (3335 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
|
 |
Intellisence not working in web.config?
Paul Hayman (3323 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
|
 |
Cleaning a string using a regular expression ready for placing in a URL
Paul Hayman (3054 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#}
|
 |
Getting the ProviderUserKey for the Current User
Paul Hayman (2915 views)
Getting the ProviderUserKey for the Current User
The following gets the ProviderUserKey for the current user.
#c#(Guid)Membership.GetUser().ProviderUserKey
|
 |
Microsoft XNA (Beta) Released
Paul Hayman (2895 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
|
 |
Returning a Distinct list of values from an array or IEnumerable cllection
Paul Hayman (2817 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'
|
 |
Scrollbar CSS style generator
Paul Hayman (2768 views)
Scrollbar CSS style generator
Excellent online tool for generating css for scrollbars
http://iconico.com/CSSScrollbar/
|
 |
Mail and News Regular Expression
Paul Hayman (2765 views)
Mail and News Regular Expression
#c#string pattern = @"(?<ignore>(^|\s|\W)[\W*])?(?<uri>((mailto|news){1}:[^(//\s,)][\w\d:#@%/;$()~_?\+-=\\\.&]+))"
#c#
|
 |
Reading a key from the registry in c#
Paul Hayman (2709 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
|
 |
Convert to and from Hex
Paul Hayman (2660 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);
|
 |
Using a .Net 2.0 anonymous delegate when generating a thumbnail
Paul Hayman (2655 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
|
 |
Generating a resized image with maximum image quality
Paul Hayman (2622 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
|
 |
Adding a Favicon to your site
Paul Hayman (2528 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/
|
 |
Regex for a HTML tag
Paul Hayman (2486 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.
|
 |
What is a FavIcon
Paul Hayman (2393 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 (2387 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 (2339 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 (2324 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)
|
 |
By Invitation Only
Paul Hayman (2258 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
|
 |
GeekZilla Google Analytics Report August 07
Paul Hayman (2249 views)
GeekZilla Google Analytics Report August 07
[[geekzila_august.gif]]
|
 |
Comments now use Wiki text
Paul Hayman (2224 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
|
 |
Non Capturing Groups
Paul Hayman (2127 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
|
 |
Great site for Vista WallPaper and more!
Paul Hayman (2098 views)
Great site for Vista WallPaper and More
http://neosmart.net/gallery/v/wallpapers/Vista/official/
|
 |
StringOrDBNull method
Paul Hayman (2074 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 Google Analytics Report July 07
Paul Hayman (2064 views)
GeekZilla Google Analytics Report July 07
[[last30days.gif]]
|
 |
geekzilla preparing for a facelift
Paul Hayman (1869 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.
|
 |
AS2 removeMovieClip not unloading my movie
Paul Hayman (1703 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
|
 |
Excellent IIS Metabase Helper
Paul Hayman (1683 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.
|
 |
Browser version detection in Javascript
Paul Hayman (1547 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
|
 |
Instanciating an object from it's type name
Paul Hayman (1518 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
|
 |
Introducing Microsoft Silverlight
Paul Hayman (1486 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
|
 |
Visual Studio Orcas Beta 1 Available
Paul Hayman (1469 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
|
 |
Stopping Focus Highlight on a mx.controls.TextInput in ActionScript on TAB
Paul Hayman (1324 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:
|
 |
FTP series codes
Paul Hayman (971 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.
|
 |
DateTime.ToString() Patterns
Paul Hayman (753 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
|
 |
Select a list of databases missing Primary keys
Paul Hayman (695 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
|
 |
DateTime.ToString() Patterns
Paul Hayman (688 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
|
 |
GeekZilla Google Analytics Report July 2010
Paul Hayman (677 views)
GeekZilla Google Analytics Report July 2010
[[geekzila_july_2010.gif]]
|
 |
Output Exchange Message Tracking Log to CSV or Excel
Paul Hayman (526 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
|