Generalhttp://www.geekzilla.co.uk/Innovation Team's dumping grounden-usTue, 10 Jun 2003 04:00:00 GMTTue, 10 Jun 2003 09:41:01 GMTGeekZilla.co.ukeditor@GeekZilla.co.ukwebmaster@GeekZilla.co.uk Nested Master Page Events not being called http://www.geekzilla.co.uk/viewE07AA87A-F88E-4570-A504-4FB5FED36F56.htm 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 often you need to nest master pages to create complex repeatable layouts. The Feature In my child MasterPage I decided to put some code in the Page_Load to populate a related menu, and it wasn't being called....... very strange.. The Top level MasterPages' events were being called, but the child's weren't! Solution I'm not sure why it defaults to false but.. you need to change the AutoEventWireup property to '''true''' in the Master Directive in the MasterPage. If this has caught you out, here's the solution. 9/10/2008 http://www.geekzilla.co.uk/viewE07AA87A-F88E-4570-A504-4FB5FED36F56.htm The easiest Hex string to/from byte array I've found http://www.geekzilla.co.uk/view11A5080D-B173-41C2-A6CD-F653593B0F74.htm 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 18/4/2008 http://www.geekzilla.co.uk/view11A5080D-B173-41C2-A6CD-F653593B0F74.htm Instanciating an object from it's type name http://www.geekzilla.co.uk/view59C67C5E-91E5-484B-B997-F2528F5C19F4.htm Instanciating an object from it's type name Instanciating a control from it's type name is easy.. One thing you may run into is that in some cases the type name needs to be a fully qualified name.. You can get this name like so: 18/3/2008 http://www.geekzilla.co.uk/view59C67C5E-91E5-484B-B997-F2528F5C19F4.htm Returning the first few items from an Array list or IEnumerable collection http://www.geekzilla.co.uk/view3B286690-73F9-41B2-A882-DDAD91647B7F.htm 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) Basic example of using .Take() The output Only the first 5. Example of using .Take() when binding an IEnumerable object to a repeater You may also like to take a look at the .Skip(int) method. It can be used in conjunction with .Take() to help you with paging object data. 20/2/2008 http://www.geekzilla.co.uk/view3B286690-73F9-41B2-A882-DDAD91647B7F.htm Returning a Distinct list of values from an array or IEnumerable cllection http://www.geekzilla.co.uk/viewAC42E918-3A03-45B1-B8EE-2068ACC1DA1C.htm 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't have to look very far before I discovered the .Distinct() method. See example below: The output? This triggered me to look at some of the other IEnumerable methods I'd ignored. My favourites so far are: {.Take(int)}http://www.geekzilla.co.uk/View3B286690-73F9-41B2-A882-DDAD91647B7F.htm .Skip(int) .Reverse() 20/2/2008 http://www.geekzilla.co.uk/viewAC42E918-3A03-45B1-B8EE-2068ACC1DA1C.htm Converting a String to a ByteArray in c# http://www.geekzilla.co.uk/view231789E5-CD19-40CC-80AE-ED42943DF2CE.htm 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"); 9/12/2007 http://www.geekzilla.co.uk/view231789E5-CD19-40CC-80AE-ED42943DF2CE.htm Reading a key from the registry in c# http://www.geekzilla.co.uk/viewA77C2D42-E40F-4F1C-9A2B-3D89A8544FEF.htm Reading a key from the registry in c# The following c# code shows how to read a key value from the registry. 9/12/2007 http://www.geekzilla.co.uk/viewA77C2D42-E40F-4F1C-9A2B-3D89A8544FEF.htm Specifying an originator IP Address on a WebService Request using ServicePoint and HttpWebRequest http://www.geekzilla.co.uk/viewAEB5BC13-938A-4DCD-8ACA-9CD2C4A3E065.htm 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 uses the default machine IP address. I read some posts about specifying only the IP Address you wanted the request to originate from in IIS 6.0 but that didn't help me at all.. I guess this was because mine were on the same NIC. It took me a while to come up with this solution and I lept for joy when it worked, and made Paul Marshall jump out of his skin. Create a wrapper for your the Web Service you want to call The following code shows my wrapped request to a What's My Ip service: I'd really like to create a Generic wrapper that didn't need to inherit the 2rd party service.. Perhaps using Generics?? Implementation You can see below, I'm specifying the IP address I want the request to originate from. If the IP address does not exist, it will use the machine default. I hope you found this article in time :) 4/12/2007 http://www.geekzilla.co.uk/viewAEB5BC13-938A-4DCD-8ACA-9CD2C4A3E065.htm Regex match html content without screwing up the tags http://www.geekzilla.co.uk/view86FE27C3-E286-4EC7-8275-6E0D8BB58C42.htm 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: If I wanted to bold all occurances of geekzilla, I'd usually do this: .. unfortunately, when dealing with HTML rather than just text, this will screw my tag and produce the following We did a lot of googling and found loads of people discussing ways to ignore the tags. Suggetions rainged from sax parsers to character by character loops (nasty). Armed with an excellent regex for matching an entire HTML tag we came up with the following solution Our Solution Use a custom Regex match evaluator to ignore any tags. This works well and is very fast. There may be a slicker way to do this, I hope someone is inspired enough to figure it out and post a comment :) 26/11/2007 http://www.geekzilla.co.uk/view86FE27C3-E286-4EC7-8275-6E0D8BB58C42.htm Excellent IIS Metabase Helper http://www.geekzilla.co.uk/view892617D9-06D4-4F77-A47A-1611AA790398.htm 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. 7/11/2007 http://www.geekzilla.co.uk/view892617D9-06D4-4F77-A47A-1611AA790398.htm Getting the Virtual Path of a Request in c# http://www.geekzilla.co.uk/viewC93F8521-8014-4CB9-8989-F2E2403A8D76.htm Getting the Virtual Path of a Request in c# This simple bit of code will get you the '''Virtual Path''' of your current request. Example Usage Notes Don't forget to include: 5/11/2007 http://www.geekzilla.co.uk/viewC93F8521-8014-4CB9-8989-F2E2403A8D76.htm Sorting an XML document in C# using XSL http://www.geekzilla.co.uk/viewA41FF312-8AED-4E53-BF6D-64D1DC48812D.htm 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 an XslCompiledTransform object to apply an XSL transformation. The output is written to a StringBuilder and reloaded into the '''successes''' XML document. The XSL in my SuccessSort.xsl document The XML inside my successes XmlDocument 20/6/2007 http://www.geekzilla.co.uk/viewA41FF312-8AED-4E53-BF6D-64D1DC48812D.htm Convert to and from Hex http://www.geekzilla.co.uk/view5798A4E2-566E-4A55-8CFE-42FDA7597820.htm Convert to and from Hex Convert from an int to Hex Convert from Hex to an int #c#int result = int.Parse("FF", System.Globalization.NumberStyles.HexNumber); 15/11/2006 http://www.geekzilla.co.uk/view5798A4E2-566E-4A55-8CFE-42FDA7597820.htm "This row already belongs to another table" Error http://www.geekzilla.co.uk/view37EB5230-5B79-4D00-800C-52D7A46CFB15.htm "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 simplified the code below from what I was actually doing in the loop, but you'll get the idea. The correct way to achieve this is to clone dt2 on dt1, this creates the appropriate columns, then when you want to copy the row from dt1 into dt2 you use the ImportRow Method. Once I'd found the solution to this problem it made perfect sense. If you've just got this error, I hope this helped you out. :-) Time for a (b) 24/10/2006 http://www.geekzilla.co.uk/view37EB5230-5B79-4D00-800C-52D7A46CFB15.htm Why we use C# for .NET development http://www.geekzilla.co.uk/view026313AC-108F-4EA1-90A2-5E5BE0DEE0F2.htm 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 use VB rather than C#. Having spent some time using both langauges I disagree with this decision. I am not one to ignore company policy but I will try to change it where I think it is incorrect. So, I spent a little time putting a SOAP (summary on a page) together to present to our chief architect. I expect there are many companies out there with a similar policy, so I thought I would post this so you could share my reasonings and perhaps change your own company policies. I wouldn't be appropriate to post the original but here is a public version: SOAP - .NET Language Preference Summary Java is the preferred development platform within our company, but where close coupling with Microsoft technologies is required, development using the Microsoft .NET Framework may be required or preferred. In an aim to reduce the number of languages supported by our company, a decision has been made to select a preferred language for the .NET platform. Our company has selected VB .NET as the preferred language for .NET development. The reasoning behind this is that we already have live applications written using VB .NET (although there are also live C# applications within our company). The status of C# is that it may be used where an application is already developed using this language, but not for new projects. This SOAP proposes switching the status of the VB. NET and C# languages so that C# is the preferred language and existing applications in VB .NET may still be maintained. Operational Perspective The reasoning behind this proposal is as follows: * VB .NET is significantly different to Java in terms of syntax and structure. C# is based on the Java/C++ syntax. VB .NET developers will have a steeper learning curve when adopting Java than C# developers. For this reason C# lends itself better to being a secondary language in a Java based organisation. * The .NET CLR (Common Language Infrastructure) has been submitted to ECMA and accepted. C# has the same status, http://msdn.microsoft.com/netframework/ecma/ . VB .NET has not. C# is better protected than VB .NET to changes in strategic direction. * Both VB .NET and C# have been used within our company to develop live applications. * Typically developers migrated from VB6 to VB .NET as this reduced the learning curve. However the .NET environment is significantly different from VB6, even though it looks superficially similar. The migration from VB6 to VB .NET can result in poorly designed VB6 style solutions running in the .NET framework. * Visual Studio 2005 comes with JLCA (Java Language Conversion Assistant) allowing Java code to be ported to C#, http://msdn.microsoft.com/vstudio/downloads/tools/jlca/ . There is no comparable tool for VB .NET. * C# provides the ability to work with C/C++ style pointers. This is rarely required and should be avoided. The exception to this rule is some forms of interoperability with legacy Microsoft code. VB .NET does not have this capability. * C# supports Java style code documentation – where definitions of properties and methods are commented in such a way as to make the component interfaces self documenting. VB .NET does not support this. * Visual Studio .NET itself was written using C#. Community support for C# is wider than for VB both inside and outside Microsoft, http://blogs.msdn.com/categories , http://www.technorati.com/search/vb c.f. http://www.technorati.com/search/c# . Industry wide there is more demand for C# as shown by the following link: http://www.indeed.com/jobtrends?q=C%23%2C+VB.NET . Financial Perspective * In terms of the cost of multi-skilled developers, the "C# & Java" skillset should be cheaper than "VB & Java" due to the languages similarities. Not only does this relate to less training but also a higher quality of code/output as the developer is more likely to be highly competent in both languages. * The lack of case sensitivity in VB means that there can be no common coding standards across Java/VB as there could be across Java/C#. This further increases the cost of cross training and maintaining those skills. * The internet is the first stop when a development problem is encountered, and here the significantly larger online C# community reduces time required to resolve problems. * The greater industry-wide take up of C# (compared to VB) means that more developers are available to recruit. * Most C# developers were previously Java or C/C++ developers, and most VB developers come from a VB5/6 background. As a result the average C# developer will have more background in object oriented design (and is more likely to be to be competent in Java also). * I don't believe that there is much wrong per se with VB, it's the peripheral aspects such as developer background, community support, and skills availability that make the difference. * As a result I suggest that C# developers will, on average, be more productive than their VB counterparts, saving our company money and time. Conclusion The differences between VB. NET and C#, as standalone languages, are fairly minimal. C# can do very few things that VB .NET cannot, and VB .NET provides a slightly easier migration path for existing Microsoft VB developers. However, in the context of Java being the primary language in the organisation, C# is a considerably better fit as a preferred .NET language. Combined with C#’s status as a ratified standard this provides a strong argument to switch the statuses of VB .NET and C# within the organisation. .... The argument is under review here still so I would appreciate any constructive commments... 15/9/2006 http://www.geekzilla.co.uk/view026313AC-108F-4EA1-90A2-5E5BE0DEE0F2.htm Bug in VS2005? Using Typed DataSets with SQL 2005 and stored procedures http://www.geekzilla.co.uk/view72C81AA0-44A5-4E2C-8903-B1EA7D7643EA.htm 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 have found a couple of problems with them when using them with full SQL Server 2005 and stored procedures. '''Problem 1:''' The first problem is basically that the wizard generates stored procedures in the Schema of the user in the connection string. Regardless of whether SQL user or Windows Authentication are used. You probably wil not have created this schema in the database and so the wizard works fine until the finish step where you see the following message... You might change the default Schema to dbo for the user, the wizard ignores this and performs 'CREATE PROCEDURE [user].[spName]...', very annoying. So, you create a schema in your database with the name of the user (and the user access to it) and this problem is resolved. '''Problem 2:''' The next problem you will see is the message: The reason for this is that the stored procedures are created in the user schema whilst the GetData/Fill/insert/update/delete methods still use the dbo Schema. I couldn't find a way to stop this other than changing the properties of the table adapter manually after configuring. However you may note that GenerateDBDirect methods is still set to true in the table adapter properties and the methods are infact generated. This results in ... '''Problem 3:''' When you run your code you see a run time error "Could not find stored procedure 'dbo.yourProcName' " What I ended up doing was to run a script (http://www.geekzilla.co.uk/View4384ACEC-8C9D-452A-83F6-230FFE43C17B.htm) to move my user.spXXX to dbo.spXXX , not ideal but the Dataset works fine after this. '''All sorted...''' Once you aware of what the wizard is doing - creating in user schema and referring to dbo schema - it becomes quite easy to cope with (if not agree with). For a while its behaviour seemed quite random, especially as I had some existing procs in the dbo schema and so some tables worked fine as they created new procs in the user schema and pointed at existing ones in the dbo schema. My final thought is - I get the impression Typed Datasets wasn't tested with SQL Server and stored procedures. But this won't stop me from using them. I hope this is fixed in a service pack soon. 14/9/2006 http://www.geekzilla.co.uk/view72C81AA0-44A5-4E2C-8903-B1EA7D7643EA.htm Authenticated HTTPRequests (Using Credentials) http://www.geekzilla.co.uk/viewC5E6201A-DFC1-4091-8145-5A893504C0E4.htm 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 fails - even after authenticating. It turns out that making a call to a webService is not too hard anyway and adding the credentials is just a single extra line of code, as shown in the sample below... This example uses the Cisco AXL interface to request a list of phones that match the description. 4/9/2006 http://www.geekzilla.co.uk/viewC5E6201A-DFC1-4091-8145-5A893504C0E4.htm Web service calls from javascript using ATLAS (part 2) - Complex return types http://www.geekzilla.co.uk/viewF266ADEB-8F62-4E92-8036-1D2436C2DE3A.htm 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 javascript. Lets expand from the previous example with the web service below... You need to add reference to this web service to your ASP.NET page. This is achieved in exactly the same way as before... You can now make JavaScript calls to the web service as shown below... I was very impressed that the properties of the c# class are now available to me in javascript. I hope you are too. I have to say, credit goes to Paul Hayman who originally pointed this out to me. Credit also to the ATLAS team of course! #$#<a href=http://www.geekzilla.co.uk/View7DA902AA-513E-48D2-AD02-0F1A1946A999.htm >Link to part three of this article</a> 25/8/2006 http://www.geekzilla.co.uk/viewF266ADEB-8F62-4E92-8036-1D2436C2DE3A.htm DateTime.ToString() Patterns http://www.geekzilla.co.uk/view00FF7904-B510-468C-A2C8-F859AA20581F.htm 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 MMMM yyyy|| H:mm Tuesday, 22 August 2006 6:30 || ||5|| dddd, dd MMMM yyyy|| h:mm tt Tuesday, 22 August 2006 6:30 AM || ||6|| dddd, dd MMMM yyyy HH:mm:ss|| Tuesday, 22 August 2006 06:30:07 || ||7|| MM/dd/yyyy HH:mm|| 08/22/2006 06:30 || ||8|| MM/dd/yyyy hh:mm tt|| 08/22/2006 06:30 AM || ||9|| MM/dd/yyyy H:mm|| 08/22/2006 6:30 || ||10|| MM/dd/yyyy h:mm tt|| 08/22/2006 6:30 AM || ||10|| MM/dd/yyyy h:mm tt|| 08/22/2006 6:30 AM || ||10|| MM/dd/yyyy h:mm tt|| 08/22/2006 6:30 AM || ||11|| MM/dd/yyyy HH:mm:ss||08/22/2006 06:30:07|| ||12|| MMMM dd|| August 22 || ||13|| MMMM dd|| August 22 || ||14|| yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK|| 2006-08-22T06:30:07.7199222-04:00 || ||15|| yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK|| 2006-08-22T06:30:07.7199222-04:00 || ||16|| ddd, dd MMM yyyy HH':'mm':'ss 'GMT'|| Tue, 22 Aug 2006 06:30:07 GMT || ||17|| ddd, dd MMM yyyy HH':'mm':'ss 'GMT'|| Tue, 22 Aug 2006 06:30:07 GMT || ||18|| yyyy'-'MM'-'dd'T'HH':'mm':'ss|| 2006-08-22T06:30:07 || ||19|| HH:mm|| 06:30 || ||20|| hh:mm tt|| 06:30 AM || ||21|| H:mm|| 6:30 || ||22|| h:mm tt|| 6:30 AM || ||23|| HH:mm:ss|| 06:30:07 || ||24|| yyyy'-'MM'-'dd HH':'mm':'ss'Z'|| 2006-08-22 06:30:07Z || ||25|| dddd, dd MMMM yyyy HH:mm:ss|| Tuesday, 22 August 2006 06:30:07 || ||26|| yyyy MMMM|| 2006 August || ||27|| yyyy MMMM|| 2006 August || The patterns for DateTime.ToString ( 'd' ) : ||0|| MM/dd/yyyy|| 08/22/2006 || The patterns for DateTime.ToString ( 'D' ) : ||0|| dddd, dd MMMM yyyy|| Tuesday, 22 August 2006 || The patterns for DateTime.ToString ( 'f' ) : ||0|| dddd, dd MMMM yyyy HH:mm|| Tuesday, 22 August 2006 06:30 || ||1|| dddd, dd MMMM yyyy hh:mm|| tt Tuesday, 22 August 2006 06:30 AM || ||2|| dddd, dd MMMM yyyy H:mm|| Tuesday, 22 August 2006 6:30 || ||3|| dddd, dd MMMM yyyy h:mm|| tt Tuesday, 22 August 2006 6:30 AM || The patterns for DateTime.ToString ( 'F' ) : ||0|| dddd, dd MMMM yyyy HH:mm:ss|| Tuesday, 22 August 2006 06:30:07 || The patterns for DateTime.ToString ( 'g' ) : ||0|| MM/dd/yyyy HH:mm|| 08/22/2006 06:30 || ||1|| MM/dd/yyyy hh:mm|| tt 08/22/2006 06:30 AM || ||2|| MM/dd/yyyy H:mm|| 08/22/2006 6:30 || ||3|| MM/dd/yyyy h:mm tt|| 08/22/2006 6:30 AM || The patterns for DateTime.ToString ( 'G' ) : ||0|| MM/dd/yyyy HH:mm:ss|| 08/22/2006 06:30:07 || The patterns for DateTime.ToString ( 'm' ) : ||0|| MMMM dd|| August 22 || The patterns for DateTime.ToString ( 'r' ) : ||0|| ddd, dd MMM yyyy HH':'mm':'ss 'GMT'|| Tue, 22 Aug 2006 06:30:07 GMT || The patterns for DateTime.ToString ( 's' ) : ||0|| yyyy'-'MM'-'dd'T'HH':'mm':'ss|| 2006-08-22T06:30:07 || The patterns for DateTime.ToString ( 'u' ) : ||0|| yyyy'-'MM'-'dd HH':'mm':'ss'Z'|| 2006-08-22 06:30:07Z || The patterns for DateTime.ToString ( 'U' ) : ||0|| dddd, dd MMMM yyyy HH:mm:ss|| Tuesday, 22 August 2006 06:30:07 || The patterns for DateTime.ToString ( 'y' ) : ||0|| yyyy MMMM 2006 August || Building a custom DateTime.ToString Patterns The following details the meaning of each pattern character. Not the '''K''' and '''z''' character. ||'''d'''||Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero|| ||'''dd'''||Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero|| ||'''ddd'''||Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)|| ||'''dddd'''||Represents the full name of the day of the week (Monday, Tuesday etc)|| ||'''h'''||12-hour clock hour (e.g. 7)|| ||'''hh'''||12-hour clock, with a leading 0 (e.g. 07)|| ||'''H'''||24-hour clock hour (e.g. 19)|| ||'''HH'''||24-hour clock hour, with a leading 0 (e.g. 19)|| ||'''m'''||Minutes|| ||'''mm'''||Minutes with a leading zero|| ||'''M'''||Month number|| ||'''MM'''||Month number with leading zero|| ||'''MMM'''||Abbreviated Month Name (e.g. Dec)|| ||'''MMMM'''||Full month name (e.g. December)|| ||'''s'''||Seconds|| ||'''ss'''||Seconds with leading zero|| ||'''t'''||Abbreviated AM / PM (e.g. A or P)|| ||'''tt'''||AM / PM (e.g. AM or PM|| ||'''y'''||Year, no leading zero (e.g. 2001 would be 1)|| ||'''yy'''||Year, leadin zero (e.g. 2001 would be 01)|| ||'''yyy'''||Year, (e.g. 2001 would be 2001)|| ||'''yyyy'''||Year, (e.g. 2001 would be 2001)|| ||'''K'''||Represents the time zone information of a date and time value (e.g. +05:00)|| ||'''z'''||With DateTime values, represents the signed offset of the local operating system's time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)|| ||'''zz'''||As z but with leadin zero (e.g. +06)|| ||'''zzz'''||With DateTime values, represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00)|| ||'''f'''||Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. || ||'''ff'''||Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.|| ||'''fff'''||Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.|| ||'''ffff'''||Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. || ||'''fffff'''||Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. || ||'''ffffff'''||Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. || ||'''fffffff'''||Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. || ||'''F'''||Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero. || ||''':'''||Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds. || ||'''/''' || Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days. || ||'''"''' || Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\). || ||'''''''|| Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters. || ||'''%c''' ||Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers. || \c Represents the escape character, and displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, the application should use two escape characters ("\\"). Any other character copies any other character to the result string, without affecting formatting. || 22/8/2006 http://www.geekzilla.co.uk/view00FF7904-B510-468C-A2C8-F859AA20581F.htm Redirect a page using a Header http://www.geekzilla.co.uk/view5F6A2CD2-1C3C-442A-8912-AA8C1BF360EA.htm 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 through, to page view, lead generation and sale, with the tracking easily implemented by inserting a small snippet of JavaScript in the page. So where does the Redirect fit in? '''Affiliate''' sites merely send clicks through to merchants via an '''affiliate network''', that tracks the referral and the conversion. But to capture the information required for '''Google's Analytics''' you need to stick a page in between the viewed page and the referral to execute the '''Google Analytics''' snippet. This is relatively simple and can be achieved a number of ways, but the best method I have discovered is to use the code below. In the Page_Load you simply append a '''Header''' to Refresh the page, set the time in seconds before the Refresh occurs and supply the URL. You won't find this in the source of the page as it's passed in the HTTP response headers to the browser. Other implementations of this solution? If you have a web application that requires a user to login, you can use this in conjunction with '''Session.Timeout''' to logout a user after a period of in activity between pages in the application. I hope you find uses for this in your next '''ASP.Net''' application. ;-) 20/8/2006 http://www.geekzilla.co.uk/view5F6A2CD2-1C3C-442A-8912-AA8C1BF360EA.htm The null coalescing operator: ?? http://www.geekzilla.co.uk/view8DAF0BB4-6F4A-4579-98E4-A46C18D46A41.htm 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: The first operand '''someValue''' must be a nullable type. The above code will set the value of '''newValue''' to '''someValue''' unless it's null, then it'll set it to '''"default"'''. You could also use this inline: Another use: 20/8/2006 http://www.geekzilla.co.uk/view8DAF0BB4-6F4A-4579-98E4-A46C18D46A41.htm Restricting the number of rows in a dataview when binding to a repeater http://www.geekzilla.co.uk/viewED362E0D-8205-4947-A751-2D754AB04C64.htm 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 items at the database level using '''Set RowCount''' or '''top 10'''. In this instance, it wasn't an option and the lack of a RowCount feature on the DataView object left me needing to find another solution. The Solution After some searching, I came across a bit of code which proved helpful. The following code makes allows me to pass a DataView into an enumerable object which returns only the number of rows I'm interested in. Example Use The Enumerable Object #$#<a href="http://www.dotnetkicks.com/kick/?url=http://www.geekzilla.co.uk/ViewED362E0D-8205-4947-A751-2D754AB04C64.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.geekzilla.co.uk/ViewED362E0D-8205-4947-A751-2D754AB04C64.htm" border="0" alt="kick it on DotNetKicks.com" /></a> 16/8/2006 http://www.geekzilla.co.uk/viewED362E0D-8205-4947-A751-2D754AB04C64.htm Sending mail using Localhost and .Net 2 http://www.geekzilla.co.uk/view26D8B20C-4627-432D-9664-63AC43EAFDF8.htm 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 your to relay from your local machine. This is simply done in IIS Admin as shown below http://static.flickr.com/40/216738937_d2957f7dc3_o.png 16/8/2006 http://www.geekzilla.co.uk/view26D8B20C-4627-432D-9664-63AC43EAFDF8.htm Code snippet for 'protected void MethodName(object sender, EventArgs e)' method http://www.geekzilla.co.uk/view50450440-FF02-4EE8-8364-649803CDE9A6.htm 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, so I wrote one. The snippet shortcut Type '''evt''' then hit '''<tab><tab>''' What the snippet outputs The Snippet Save this snippet in your snippet folder as '''evt.snippet''' (see the download links for this article) The snippet folder is typically located here: '''\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#''' or here: '''\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets''' 2/8/2006 http://www.geekzilla.co.uk/view50450440-FF02-4EE8-8364-649803CDE9A6.htm Using Regular Expressions to validate a filename in a FileUpload control http://www.geekzilla.co.uk/view9833D332-2813-43EE-9E8A-45F2B97189C3.htm 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 31/7/2006 http://www.geekzilla.co.uk/view9833D332-2813-43EE-9E8A-45F2B97189C3.htm Generating a resized image with maximum image quality http://www.geekzilla.co.uk/view0AD85443-C322-4104-9227-C86D298625BA.htm Generating a resized image with maximum image quality Here's some code I use for generating a resized image with no Jpeg compression. 31/7/2006 http://www.geekzilla.co.uk/view0AD85443-C322-4104-9227-C86D298625BA.htm Return new identity from Strongly Typed Dataset DataTable.Insert method http://www.geekzilla.co.uk/viewF2737CEE-4FCE-4215-B8CA-74D77EF64A5F.htm 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 inserted. Fortunately there is an easy way to get the Sproc and the c# method to return a reference to the object. Firstly edit your insert stored procedure adding a @return parameter and a line after the insert to set this to a suitable value. The exmaple below assumes that you are using bigint identity fields. Note that SCOPE_IDENTITY() is similar to @@IDENTITY except its scope is limited to the current command and so improves scalability. Now when you save the Dataset you see that the insert method takes two parameters, the second being a nullable long. My first thought was that Datasets should be the end of editing stored procedures but I am still impressed that the c# method declaration changes accordingly. You can call the updated method in the following way. the long? just means nullable long. After filling the table you can now use the FindByxxxID functions of the DataTable to return the DataRow object. 27/7/2006 http://www.geekzilla.co.uk/viewF2737CEE-4FCE-4215-B8CA-74D77EF64A5F.htm Getting on the Vista developers merry-go-round http://www.geekzilla.co.uk/view0F0774F1-05E5-4FE4-A805-EBCC1EB67937.htm 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 WCF libs: || OS || Runtime || SDK || Orcas Extensions || WCF || || Vista 5472.5 || July CTP || http://www.microsoft.com/downloads/details.aspx?familyid=1D7F16B3-D2D5-48F7-9494-6696117EE712&displaylang=en || None yet! || http://www.microsoft.com/downloads/details.aspx?FamilyId=E74FECC8-1278-444E-B775-21F9E8E2A586&displaylang=en || || Vista 5456 || June CTP || http://www.microsoft.com/downloads/details.aspx?FamilyID=d6cd6490-af1a-48c3-aebd-389daf45003c&DisplayLang=en || http://www.microsoft.com/downloads/details.aspx?FamilyID=1a994549-94cb-4f61-903d-a8c8e453eef4&DisplayLang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=63A80A4B-BD27-4124-A2A5-61786ADB626E&displaylang=en || || Vista 5384.4 || Beta 2 || http://www.microsoft.com/downloads/details.aspx?FamilyId=13F8E273-F5EA-4B7B-B022-97755838DB94&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=31F9F15D-00E0-4241-8014-2F12679119AA&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=5C080096-F3A0-4CE4-8830-1489D0215877&displaylang=en || || XP / W2K3 || http://www.microsoft.com/downloads/details.aspx?FamilyId=62057A6F-185F-41DB-ABE5-678F6FC388F0&displaylang=en || http://www.microsoft.com/downloads/details.aspx?familyid=1D7F16B3-D2D5-48F7-9494-6696117EE712&displaylang=en || None yet! || http://www.microsoft.com/downloads/details.aspx?FamilyId=E74FECC8-1278-444E-B775-21F9E8E2A586&displaylang=en || || XP / W2K3 || http://www.microsoft.com/downloads/details.aspx?FamilyId=8D09697E-4868-4D8D-A4CF-9B82A2AE542D&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyID=d6cd6490-af1a-48c3-aebd-389daf45003c&DisplayLang=en || http://www.microsoft.com/downloads/details.aspx?FamilyID=1a994549-94cb-4f61-903d-a8c8e453eef4&DisplayLang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=63A80A4B-BD27-4124-A2A5-61786ADB626E&displaylang=en || || XP / W2K3 || http://www.microsoft.com/downloads/details.aspx?FamilyId=4A96661C-05FD-430C-BB52-2BA86F02F595&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=13F8E273-F5EA-4B7B-B022-97755838DB94&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=31F9F15D-00E0-4241-8014-2F12679119AA&displaylang=en || http://www.microsoft.com/downloads/details.aspx?FamilyId=5C080096-F3A0-4CE4-8830-1489D0215877&displaylang=en || The Vista versions all install the relevant runtime as part of the os install. #$#<a href="http://www.dotnetkicks.com/kick/?url=http://www.geekzilla.co.uk/View0F0774F1-05E5-4FE4-A805-EBCC1EB67937.htm"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.geekzilla.co.uk/View0F0774F1-05E5-4FE4-A805-EBCC1EB67937.htm" style="border:none;" border="0" alt="kick it on DotNetKicks.com" /></a> 27/7/2006 http://www.geekzilla.co.uk/view0F0774F1-05E5-4FE4-A805-EBCC1EB67937.htm Need a high resolution timer? http://www.geekzilla.co.uk/view4D608741-7A43-4626-A959-8EC2D14C7193.htm 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: Call like this: 26/7/2006 http://www.geekzilla.co.uk/view4D608741-7A43-4626-A959-8EC2D14C7193.htm Missing App.Path http://www.geekzilla.co.uk/view539AC7FD-E30A-40B2-A427-7402A055BA4E.htm 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. #c# string Location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); 26/7/2006 http://www.geekzilla.co.uk/view539AC7FD-E30A-40B2-A427-7402A055BA4E.htm Extending Strongly Typed Datasets http://www.geekzilla.co.uk/view6FFCCB67-2483-437D-A6B6-08B378B5B23C.htm 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 were generated by hand or by a utility such as CodeSmith then the classes could just be edited to add function as required (though most of the benefits of code generation are lost once the generated code is edited). The STD source is of course auto-generated from the xsd file, a convienient way to view the C# source is to type the STD name and use the context menu to 'Go To Definition', or press F12. This will open a c# source file with a guid name. You can edit this file but it will be overwritten each time the xsd is compiled. You can add new methods and properties to the STD classes by using partial classes. First create a new cs (or vb if you swing that way) file with the filename same as your xsd - for example 'ObjectSTD.cs'. Edit the class definition adding the partial keyword as below. You can add a new method to the ObjectRow class within the ObjectSTD class with the following code... Note that private properties and methods are available and intellisense supports these. 23/7/2006 http://www.geekzilla.co.uk/view6FFCCB67-2483-437D-A6B6-08B378B5B23C.htm Highlighting keywords in text using Regex.Replace (Perfect for SEO) http://www.geekzilla.co.uk/view9106A22C-16B7-49C7-AC47-0CE9A1106CC8.htm 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/SearchEngineOptimisation.aspx Example The following example shows how I achieved this although it does contain dummy data. I created a new C# 2005 Console App and added the following to the Main method: Then added the follwoing static methods: Result Explanation First of all, I needed to swap out the comma+space (or just comma in some cases) for the pipe character ''''(regex or)'''' I then prepared a Regex object for the main keyword replace: You can see I chose to ignore case and match based on Singleline. Singleline ignores new line characters mid match.. for example two words seperated by newline rather than space. Now comes the replace. You'll notice that I pass a MatchEvaluator into the replace method. I use this to choose what to replace the match with. The MatchEval method only looks for the first group match, that's all I need. Had the master regular expresion contained two groups, the MatchEval method would have required a second '''If'''. 20/7/2006 http://www.geekzilla.co.uk/view9106A22C-16B7-49C7-AC47-0CE9A1106CC8.htm Triple DES encryption wrapper http://www.geekzilla.co.uk/view7B360BD8-A77C-4F1F-BCA0-ACD0F6795F61.htm Triple DES encryption wrapper Here is a handy wrapper for Triple DES encryption: Example usage 18/7/2006 http://www.geekzilla.co.uk/view7B360BD8-A77C-4F1F-BCA0-ACD0F6795F61.htm Generic Lists are All You Will Ever Need http://www.geekzilla.co.uk/viewCFB7B5D1-0BC7-4D49-AB79-4F973BD1CF81.htm 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 that inherited from CollectionBase and then implemented all of the usual functionality. An example is shown below :- But now this has all been replaced with As you can see a massive code reduction with no loss of functionality, making it simplier to use and easier to maintain. 14/7/2006 http://www.geekzilla.co.uk/viewCFB7B5D1-0BC7-4D49-AB79-4F973BD1CF81.htm Convert a DataReader to a DataTable http://www.geekzilla.co.uk/view62827695-E156-4754-9126-2CA97348FACA.htm 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 the Framework you just need to know where to look. So here is the simple way to convert a DataReader to a DataTable. Create a class Inheriting from DataAdapter Then to use it : Attached is a sample project showing the use of this. 13/7/2006 http://www.geekzilla.co.uk/view62827695-E156-4754-9126-2CA97348FACA.htm EasyHTTP http://www.geekzilla.co.uk/viewB5BAB652-EBA2-44F8-8F30-0588E092873A.htm EasyHTTP EasyHTTP is a simple class which exposes the HTTP functionality of .NET as a number of simpler methods. #c#} 20/6/2006 http://www.geekzilla.co.uk/viewB5BAB652-EBA2-44F8-8F30-0588E092873A.htm CLR Stored Procedure for searching files http://www.geekzilla.co.uk/view4E325877-BACA-4E37-A5C8-FA4AC0B8428D.htm 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 learning excersise. This article details the steps I went through to get to the end result. Pre-requesits *Visual Studio 2005 *SQL Server 2005 The SQL project From Visual studio, create a new C# database project. The new project wizard will ask you to specify a database for your project. In this instance, this is only used when you deploy the stored procedure. Once the project is created, add a new stored procedure to the project by right clicking the project and choosing '''Add New Item..'''. Specify the input parameters for the stored procedure in the auto generated function header. For this example: The file processor The following code processes a text file and builds up a list of occurances. Returning the results The SqlContext.Pipe object is the key to communicating with SQL. There are four methods on the Pipe object which can be used for returning data. ||Send()||Multiple rows from a reader, one record or some text|| ||SendResultsStart()||Sends one row (SqlDataRecord) and configures the pipe for sending more rows|| ||SendResultsRow()||Sends one row|| ||SendResultsEnd()||Tells the Pipe we've finished sending data|| To return a single row you need to create a SqlDataRecord. Below is an example of creating a SqlDataRecord with one varchar column. If we wanted to only return one row we'd use send.. as below The finised stored procedure Deploying the Stored Procedure Deploying the stored procedure is easy, or so it seemed. Right click the project in Solution Explorer, choose Deploy. This worked, unfortunately this stored procedure would like to access a file, this requires the EXTERNAL_ACCESS permission. EXTERNAL_ACCESS To mark the stored proc as requiring EXTERNAL_ACCESS you need to bring up the properties window for the project. On the Database tab, change the '''Permission Level''' to '''"External"'''. TRUSTWORTHY One last thing, before you can deploy an EXTERNAL_ACCESS stored procedure, you will need to ensure that the target database is marked as [TRUSTWORTHY]. Use the following T-Sql to do this. Lets deploy Once you've ensured the EXTERNAL_ACCESS and TRUSTWORTH settings are correct, try deploying the stored proc. It should deploy with no problems.. '''(I was connected to the database as SA when I tried)''' Calling the Stored Procedure Summary Creating CLR stored procedures is easy. Creating CLR stored procedures which need access to external objects like files, web services etc is also pretty easy once you know what to do about security issues. Further Reading http://www.devx.com/codemag/Article/31193/0/page/5 http://blogs.msdn.com/lcris/archive/2005/09/26/474202.aspx 16/6/2006 http://www.geekzilla.co.uk/view4E325877-BACA-4E37-A5C8-FA4AC0B8428D.htm Writing CLR Stored Procedures in C# http://www.geekzilla.co.uk/view6C0ECA41-80B9-4EA9-A232-FF9C5AEE68C3.htm 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 learn to use Visual Studio. This article covers the basics of C# and Visual Studio using a basic stored procedure as an example. It's written using the April CTP of SQL Server 2005. ''This article shows you how http://www.sqlteam.com/item.asp?ItemID=21927 '' 15/6/2006 http://www.geekzilla.co.uk/view6C0ECA41-80B9-4EA9-A232-FF9C5AEE68C3.htm IsGuid() (Regular Expression Guid Match) http://www.geekzilla.co.uk/view8AD536EF-BC0D-427F-9F15-3A1BC663848E.htm IsGuid() (Regular Expression Guid Match) A regular expression for validating a string as being a Guid is.. Example usage Below is a function I try to keep handy which tests a string for a Guid and returns True or False. 14/6/2006 http://www.geekzilla.co.uk/view8AD536EF-BC0D-427F-9F15-3A1BC663848E.htm class.Serialize() http://www.geekzilla.co.uk/view42D9A6D3-5422-4E01-8470-D01DEF1F4770.htm class.Serialize() Handly little function which I include in most classes. This function returns the object serialized as XML, perfect for logging etc. Developments Scott Peterson pointed out that the following code could a useful alternative. Good work Scott. 14/6/2006 http://www.geekzilla.co.uk/view42D9A6D3-5422-4E01-8470-D01DEF1F4770.htm Referencing ConfigurationManager http://www.geekzilla.co.uk/view36932421-B4B7-4948-BBDA-39567F616BBC.htm 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 is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings' Old way of accessing AppSettings New way of accessing AppSettings So I changed my code accordingly, but the project wouldn't compile. It turns out that you need to add a reference to System.Configuration to the project, rather than simply adding it with a using statement. This can be done as follows. Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration 14/6/2006 http://www.geekzilla.co.uk/view36932421-B4B7-4948-BBDA-39567F616BBC.htm Select a row in an asp:GridView without using a Select Command http://www.geekzilla.co.uk/view9FC28EE6-ACB0-4F51-BFE4-38B0B10134D5.htm 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. What's worse is you then have to create a '''SELECT''' command button to be able to access that line's data. Use the following code on the event OnRowDataBound to eliminate the need for the '''SELECT''' command field and save yourself some valuable space. Here is the '''HTML''' to create a GridView, I'm displaying a list of people, and the key for each record is the '''PERSON_ID'''. The key event to note is the OnRowDataBound, use the following code to create '''SELECT''' functionality on the row. Each row will then behave like a link, and when you select one it can drive the behavior of another control(s) on your page, possibly a DetailsView allowing you to INSERT a complete record to the database. 14/6/2006 http://www.geekzilla.co.uk/view9FC28EE6-ACB0-4F51-BFE4-38B0B10134D5.htm Assigning an array of strings to a variable http://www.geekzilla.co.uk/viewE9B2C57F-435F-4836-BC0C-A5955B1AC2A5.htm Assigning an array of strings to a variable Declaring a string array with hard coded data is easy. Passing hard coded array into method Likewise, passing an array of hard coded data into a method is also easy.. For example: #c#Roles.AddUsersToRole(new string[] { NewUserCreateUserWizard.UserName }, "Users"); 14/6/2006 http://www.geekzilla.co.uk/viewE9B2C57F-435F-4836-BC0C-A5955B1AC2A5.htm Evaluating Expressions http://www.geekzilla.co.uk/view8DD1EFC2-2603-479F-9DCC-F9AA991372CA.htm Evaluating Expressions You can evaluate sums in the fly using .net DataTables. This is how you do it (C# 2005). This can be pretty damn useful. On a recent project we used tokenised strings which were dynamically replaced with values read from a serialized class. Consider how powerful this can be. e.g. (VB.NET 2003) 13/6/2006 http://www.geekzilla.co.uk/view8DD1EFC2-2603-479F-9DCC-F9AA991372CA.htm