GeekZilla
General Articles
FTP series codes
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
Paul Hayman - 6,772 viewsNested Master Page Events not being called
Nested Master Page Events not being called This is the second time I've been caught out by this little feature, so I thought I'd geekzilla it for both reference and to help others. Scenario I'm a big fan of MasterPages and Themes as a design principle for web development, and
Paul Marshall - 2,575 viewsThe easiest Hex string to/from byte array I've found
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
Paul Hayman - 20,122 viewsInstanciating an object from it's type name
Instanciating an object from it's type name Instanciating a control from it's type name is easy.. string typeName = "YourNameSpace.YourObject"; Type assType = Type.GetType(typeName); object dynamicControl = Activator.CreateInstance
Paul Hayman - 1,922 viewsReturning the first few items from an Array list or IEnumerable collection
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 foun
Paul Hayman - 3,221 viewsReturning a Distinct list of values from an array or IEnumerable cllection
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
Paul Hayman - 4,688 viewsConverting a String to a ByteArray in c#
Converting a String to a Byte Array in c# Very simple.. here's how to convert a String to a Byte Array in c# byte[] yourByteArray = Encoding.ASCII.GetBytes("your string");
Paul Hayman - 4,755 viewsReading a key from the registry in c#
Reading a key from the registry in c# The following c# code shows how to read a key value from the registry. Registry.LocalMachine.OpenSubKey("SOFTWARE", true); RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\yourapp\\yourkey")
Paul Hayman - 7,947 viewsSpecifying an originator IP Address on a WebService Request using ServicePoint and HttpWebRequest
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. .n
Paul Hayman - 7,624 viewsRegex match html content without screwing up the tags
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: <a href="geekzilla.aspx">you
Paul Hayman - 18,267 viewsExcellent IIS Metabase Helper
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.
Paul Hayman - 2,110 viewsGetting the Virtual Path of a Request in c#
Getting the Virtual Path of a Request in c# This simple bit of code will get you the Virtual Path of your current request. public static string GetVirtualPath(string url) { if (HttpContext.Current.Request.Application
Paul Hayman - 18,902 viewsSorting an XML document in C# using XSL
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 follo
Paul Hayman - 20,881 viewsConvert to and from Hex
Convert to and from Hex Convert from an int to Hex String result = String.Format("{0:x2}", 255) Convert from Hex to an int int result = int.Parse("FF", System.Globalization.NumberStyles.HexNumber);
Paul Hayman - 3,165 views"This row already belongs to another table" Error
"This row already belongs to another table" Error What an annoying error!! I couldn't believe that I couldn't just add a Row from one DataTable to another, while looping around a DataTable's Rows. It turned out to be slightly more complicated than the code I had written, I've si
Paul Marshall - 141,618 viewsWhy we use C# for .NET development
Why we use C# for .NET development In the company where we work, we have a policy of using Java for all major developments. The core reason behind this being that we have a long term aspiration to being vendor and platform independent. Regards the .NET framework the policy is to
Dave Howard - 38,206 viewsBug in VS2005? Using Typed DataSets with SQL 2005 and stored procedures
Bug in VS2005? Using Typed DataSets with SQL 2005 and stored procedures I have been a fan of typed datasets since I started using them in VS2005. Using the feature with SQL Express/stored procedures, Express/SQL Statements, SQL Server/SQL Statements all generate my DAL just fine. However, I
Dave Howard - 10,193 viewsAuthenticated HTTPRequests (Using Credentials)
Authenticated HTTPRequests (Using Credentials) Recently I had to make a SOAP call to a Cisco CallManager (an IP PBX). This required that the request used basic authentication. I couldn't add a web reference as the cisco interface doesn't support GET requests, so the Visual Studio discovery
Dave Howard - 81,955 viewsWeb service calls from javascript using ATLAS (part 2) - Complex return types
Web service calls from javascript using ATLAS (part 2) - Complex return types Following on from part one which showed how to make web service calls from javscript, this article will now show the flexibility of the ATLAS framework by calling a web service that returns an object from jav
Dave Howard - 7,089 viewsDateTime.ToString() Patterns
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 ddd
Paul Hayman - 1,327,767 viewsRedirect a page using a Header
Redirect a page using a Header Any keen surfer will be familiar with Affiliate Marketing, its a huge industry with Google's Adwords driving "Pay Per Click" campaigns. Google provide the Adwords application and Google Analytics to track the effectiveness of marketing campaigns from click thr
Paul Marshall - 16,306 viewsThe null coalescing operator: ??
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: string newValue = someVa
Paul Hayman - 4,547 viewsRestricting the number of rows in a dataview when binding to a repeater
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
Paul Hayman - 13,760 viewsSending mail using Localhost and .Net 2
Sending mail using Localhost and .Net 2 I came across an old favourite today when trying to send email using the SMTP service on Local host. The error was SMTP 550 5.7.1 Unable to relay for xxxxxx What you need to do is change the security settings on the SMTP Service to allow
Greg Duffield - 3,768 viewsCode snippet for 'protected void MethodName(object sender, EventArgs e)' method
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
Paul Hayman - 4,595 viewsUsing Regular Expressions to validate a filename in a FileUpload control
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 // check anything has been uploaded if (ThumbnailImageUpload.Poste
Paul Hayman - 71,112 viewsGenerating a resized image with maximum image quality
Generating a resized image with maximum image quality Here's some code I use for generating a resized image with no Jpeg compression. public MemoryStream GetResized(Bitmap originalImage, int width, int height) {
Paul Hayman - 3,214 viewsReturn new identity from Strongly Typed Dataset DataTable.Insert method
Return new identity from Strongly Typed Dataset DataTable.Insert method Datasets are pretty good at auto generating stored procedures and wrapping c# code around them for you. However with the insert method you often want to do something with the object that you have just inserte
Dave Howard - 26,823 viewsGetting on the Vista developers merry-go-round
Getting on the Vista developers merry-go-round Trying to keep up with the various Vista Beta releases? Want to develop but not sure which version will work on your platform? Here's a useful set of links to make sure you get the right version of the runtime, SDK, Orcas VS extensions and
Mark Page - 3,435 viewsNeed a high resolution timer?
Need a high resolution timer I like to profile my code regularly to see if any changes I make during development affect performance. In .Net 1.1 there is a distinct lack of a high resolution timer object. Here's one you can use:
Lee Keable - 2,379 viewsMissing App.Path
Missing App.Path If you have the need to load resources (XSL stylesheets, images etc etc) at runtime, you may need to know the path of the currently executing code. In VB6 you'd just use good old App.Path, here is the .Net equivalent. using System.IO; string&n
Lee Keable - 3,954 viewsExtending Strongly Typed Datasets
Extending Strongly Typed Datasets Strongly Typed Datasets are a rather nice addition to VS2005 (they don't lend themselves well to acronyms however) You still need to create a database and tables and realationships but using STDs saves a writing huge amount of code. If this code
Dave Howard - 6,328 viewsHighlighting keywords in text using Regex.Replace (Perfect for SEO)
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 Example The following example shows how I achieved this althou
Paul Hayman - 27,749 viewsTriple DES encryption wrapper
Triple DES encryption wrapper Here is a handy wrapper for Triple DES encryption:
Paul Hayman - 21,906 viewsGeneric Lists are All You Will Ever Need
Generic Lists are All You Will Ever Need Generic lists have reduced the amount of code we have to write for our n-tier applications dramatically. Where they have been most uselful is in the definition of our Strongly Typed Object Collections. Previously we would have created a class th
Greg Duffield - 1,917 viewsConvert a DataReader to a DataTable
Convert a DataReader to a DataTable When working with Datareaders one of the problems i sometimes come across is binding these to 3rd party controls. A lot of controls will not bind to a DataReader but nearly all of the alwaays bind to a DataTable. All of the functionlity already exists in t
Greg Duffield - 15,372 viewsEasyHTTP
EasyHTTP EasyHTTP is a simple class which exposes the HTTP functionality of .NET as a number of simpler methods.
Barrington Haynes - 6,334 viewsCLR Stored Procedure for searching files
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
Paul Hayman - 16,041 viewsWriting CLR Stored Procedures in C#
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
Paul Hayman - 16,027 viewsIsGuid() (Regular Expression Guid Match)
IsGuid() (Regular Expression Guid Match) A regular expression for validating a string as being a Guid is.. @"^(\{{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})$" Example usage Below is a function I try to keep handy which t
Paul Hayman - 99,092 viewsclass.Serialize()
class.Serialize() Handly little function which I include in most classes. This function returns the object serialized as XML, perfect for logging etc. /// <summary> /// Serialize this object /// </summary> /// <returns>XmlDocumen
Paul Hayman - 7,486 viewsReferencing ConfigurationManager
Referencing ConfigurationManager When I started working in VS2005, I assumed that accessing your AppSettings would be the same as it was in VS2003. On compiling, the IDE served up the following warning. 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method
Barrington Haynes - 5,642 viewsSelect a row in an asp:GridView without using a Select Command
Select a row in an asp:GridView without using a Select Command ASP.Net's GridViews can be quite useful, but beware of binding them to huge datasets as this has an overhead on the ViewState. Often you'll want to display a number of columns on each line and row space becomes an issue. W
Paul Marshall - 489,772 viewsAssigning an array of strings to a variable
Assigning an array of strings to a variable Declaring a string array with hard coded data is easy. string[] newString = new string[] {"one", "two", "three"} Passing hard coded array into method Likewise, passing an array of hard coded data
Paul Hayman - 4,239 viewsEvaluating Expressions
Evaluating Expressions You can evaluate sums in the fly using .net DataTables. This is how you do it (C# 2005). string sum = "(1+2)/4"; System.Data.DataTable evaluator = new System.Data.DataTable("temp"); double result; resu
Paul Hayman - 5,271 views