Generated ASP.NET page source files on 06 Apr 05 (Add comment)

I found a really useful article about the ASP.NET page compilation process. The thing I was looking for was actually where to find the generated page source files. They’re stored in a directory like: C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files

ASP.NET syntax highlighter components on (Add comment)

For once I’m going to resist the urge to reinvent the wheel.. :) What I’ve found so far: Actipro CodeHighlighter

Casting in VB.NET on 22 Mar 05 (Add comment)

I just found a really good article on casting in .NET.

VB.NET control structures cheatsheet on 02 Mar 05 (Add comment)

If statements: If condition Then    ' do something Else    ' do something else End If For loop: For i As Int16 = start To end    ' do something Next For each: For Each item As Type In Collection    ' do something Next

Accessing embedded resource files on 01 Mar 05 (Add comment)

To get a resource from the current assembly: Stream stream = this.GetType().Assembly().GetManifestResourceStream(“namespace.file”); To get all the names of all the resources in your current assembly: string[] resources = this.GetType().Assembly.GetManifestResourceNames(); foreach(string resourceName in resources) { Debug.WriteLine(resourceName); }

Debugging clientside scripts in VS,NET 2003 on 10 Feb 05 (Add comment)

How interesting! Turns out that VS.NET 2003 actually supports debugging of clientside scripts! I’m going to miss the javascript alert function. :)

error-message-to-problem translation: Object must implement IConvertible on 03 Feb 05 (Add comment)

The error “System.InvalidCastException: Object must implement IConvertible” in the context of saving things to a database (in my case through a command object with pre-set typed parameters) means that you’re asking the command object to set a parameter with an incompatible type. In my case, I was trying to set a SqlDbType.Text field in my […]

Formatting currency on 25 Jan 05 (Add comment)

Found a rather nifty trick for formatting double values into currency strings. It’s really simple! You just specify “C” as an argument to the ToString method and it automatically generates a currency string that’s in the right format for whatever your local settings are. value.ToString(“C”); There’s lots of other stuff you can do with the […]

Handling SelectedIndexChange for a DropDownList in a Repeater on (5 comments)

Came across an interesting problem yesterday trying to handle the SelectedIndexChanged event for a DropDownList that was inside a Repeater. I found a wonderful article on Databinding that gave me most the information I needed, but their method of handling events just didn’t work for me. My first problem was that I originally did the […]

VS.NET compiling slowed by my virus checker on 13 Dec 04 (Add comment)

I wasn’t really surprised to find that my virus checker slows my VS.NET compilations somewhat, but I was surprised by exactly how much. With Macafee’s real time scanning on, my P4 with 720mb of RAM compiles about the same speed as the P600 with 128MB of RAM I was using before. When I turn off […]

Tools .NET developers can't live without on 08 Dec 04 (Add comment)

Roy Osherove’s put together a list of must-have tools for .NET developers. My favourite is definitely Resharper which is a VS.NET plugin that makes Visual Studio a lot nicer to use. If you’ve ever thought “I wish VS.NET did x”, chances are Resharper will do it. The refactoring tools alone made it worth the $100US […]

Sending email in ASP.NET on (Add comment)

Sending mail in ASP.NET is simple! You just create a message and then call the SmtpMail’s static send method: MailMessage message = new MailMessage();message.To = "me@email.com";message.From = "me@email.com";message.Subject = "An email from helen";message.Body = "Hello Helen. From Helen.";SmtpMail.Send(message); If you need to talk to a non-local server, that’s not really much more difficult. You just […]

ASP.NET and XHTML on 26 Nov 04 (Add comment)

I found a couple of interesting articles about ASP.NET and web standards when I was looking for information about seperating presentation and business logic in ASP.NET using XML. The guy from ASP.NET resources makes the argument that it’s not economically viable to put the resources into developing ASP.NET applications that return properly compliant XHTML. I […]

C# syntax for creating an abstract property on 17 Nov 04 (Add comment)

public abstract int GetX { get;}

protected internal access modifier on 10 Nov 04 (Add comment)

Here’s how you create a property (though it could be variable, method or I think even class) that can be see by things that subclass the object it belongs to and things that are in the same package: protected internal object myProperty { get { return m_property; } set { m_property = value; } } […]

Loading and saving registry information in C# on 08 Nov 04 (Add comment)

Saving info to the registry for the currently logged in user: RegistryKey key = Registry.CurrentUser.CreateSubKey(“MyRegistryKey”); key.SetValue(“MyKeyValue”, “Some value”); Loading the same info from the registry: RegistryKey key = Registry.CurrentUser.CreateSubKey(“MyRegistryKey”); if(key != null) { string keyValue = (string) key .GetValue(“MyKeyValue”); } Reference: RegistryKey Class MSDN documentation

Writing text files in C# on 05 Nov 04 (Add comment)

My quick-start file writing example for those who go months between needing to write a file. StreamWriter writer = new StreamWriter(filename, false); writer.Write(“some text”); writer.Close(); I remember it being harder than this.. Reference: Streamwriter documentation

Defining the entry point for a C# application on (Add comment)

This is the C# equivalent of the Main(String[] args) method in Java: [STAThread]static void Main() { Application.Run(new MyStartupClass());} This code usually goes in the class that defines your first windows form.

Formatting an XML string in C# on (Add comment)

Here’s a nifty trick if you’ve got a chunk of XML you want to format nicely: XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xmlStringVariable); MemoryStream memoryStream = new MemoryStream(10240); xmldoc.Save(memoryStream); string formattedXml = Encoding.ASCII.GetString(memoryStream.GetBuffer()); memoryStream.Close();

An advantage of C# properties on 04 Nov 04 (Add comment)

Just found a good reason to use properties in C# rather than public variables: they’re much easier to debug. When I was getting an unexpected value in the variable, I put a break point in the property and was able to really easily find out where it was being set.

Raising custom events in C# on 03 Nov 04 (1 comment)

First you need to declare an event in the class that’s going to raise the event. This is just like declaring a normal variable: public event EventHandler MyEvent; Then you need a method that’s going to be called to raise the event. This goes into the same class that you just declared the event in. […]

Passing Type as a parameter on 27 Oct 04 (Add comment)

Here’s a useful bit of C# code for creating a method that takes a Type as a parameter from the microsoft.public.dotnet.languages.csharp group. Calling code: MyComponent component;object myobject;MyMethod(myobject, typeof(MyComponent)); Method: public static void MyMethod(object myobject, Type type) { if(myobject.GetType() == type) { // do something }} Useful references: MSDN typeof documentation MSDN using typeof reference

Regular expressions in C# on 19 Oct 04 (Add comment)

Learnt something new today from Merak on the UK Microsoft web developer’s list. One of my early problems when writing regular expressions in C# was that I didn’t realise that is actually an escape character when used in a string in C#. So when I wanted to write an expression like this: /d/ (which means […]

NUnit problem – assembly has no TestFixtures on (1 comment)

I’ve been investigating doing unit testing in ASP.NET using NUnit. It’s a very interesting idea, particularly the idea about Test Driven Development, but I’ll post a bit more about that later. NUnit is a really nice piece of software, but I run into a problem when I tried running my first unit test. The error […]

StackOverflowException and properties on 18 Oct 04 (3 comments)

An easy way to get this exception is by refering a property to itself: public string myproperty {     set { myproperty = value; } } The exception looks like this: [StackOverflowException: Exception of type System.StackOverflowException was thrown.] Granted it’s a pretty dumb thing to do.. :)