.NET Sample Code
-
Binding a Control to an Enum
by James Crowley
Ever had an Enum (with a set of names and values) that you wanted to bind to a control like a DropDownList? Here's how.
-
Generate an Image of a Web Page
by Alan Dean
Demonstrates how to fetch images and thumbnails of web pages using a hidden web browser control.
-
A Simple ASP.NET MessageBox Class
by Lee Gunn - .NET C# Scotland
When moving from Windows Forms to ASP.NET Web Forms, an API that may be missed is that offered by the System.Windows.Forms.MessageBox Class. Here we implement it for ASP.NET!
-
Reading Binary Data in C#
by Jon Skeet
How to read binary data from a file in C# - the right way!
-
Using the Credential Management API
by Alan Dean
Following secure development best practice, an application should obtain and store user credentials securely. Microsoft has provided a means to accomplish this on the desktop: the unmanaged Credential Management API, which exposes the capability to provide a standard login experience for the user which is also secure. This code demonstrates how to create a generic dialog implementation using this API.
-
Parse a UK Date String
by James Crowley
Ever wondered why DateTime.Parse doesn't recognise non-US date format? Here's how to get it to!
-
Easy Asynchronous Programming
by Simon Soanes
A simple demonstration of how to use multithreading and delegates in .NET to execute a method that will take a long time, without locking up our main thread.
-
Dynamic thumbnail images from ASP.NET
by Brock Allen
This sample code is an IHttpHandler implementation that reads a JPG from the filesystem and dynamically generates a thumbnail sized version of the image and emits that to the response stream. What I like about this approach is that you don't need to create a file on the filesystem for the thumbnail as it's all done in memory.
-
Cross page postbacks in ASP.NET 2.0
by Brock Allen
ASP.NET 2.0 introduces the ability to have an ASPX page postback to a different ASPX page with cross page postbacks. This was done all the time in ASP but wasn’t supported in ASP.NET 1.x. Here we show you how to use this new feature.
-
Read MP3 Tag Information (ID3v1 and ID3v2)
by Erin Jones
This sample source code demonstrates how to read IP3v1 and IP3v2 tag information from MP3's, along with MPEG headers too.
-
Inserting images into Word documents using XML
by Jonathan Greensted
I've seen many, many requests on the Microsoft newsgroups asking how you can insert a picture into a Word document without saving it to the file system first. This example application described in this blog illustrates both methods for inserting a picture firstly using the Word object model (InlineShapes.AddPicture) and secondly using Word's XML support (InsertXML).
-
Windows Forms and the Idle Loop
by Mike Taulty
When you're writing Windows Forms applications it's always nice to be able to keep the UI responsive in order to avoid frustrating the user. Here's a method of completing your asynchronous work on the Application Idle loop rather than allowing another thread to wander into your Windows Forms code and then trying to deal with it by Control.Invoke.
-
Programatically Load User Controls
by Dave Wanta
How to programatically load user-controls from code behind pages and then access their properties using reflection.
-
Spoofing the Referrer using HttpWebRequest
by Dave Wanta
Here's a simple way to spoof the referrer to a web page during a web request.
-
Calculate Age
by James Crowley
How to calculate someone's age from their birth date.
-
Save a Stream to a File
by James Crowley
Demonstrates how to write a stream to a file.
-
Double buffering in .NET
by Simon Soanes
Ever wondered how to double buffer with a Graphics object so your GDI+ based game/control doesn't flicker annoyingly? Here's how!
-
Simple Object Relation Mapping with Reflection
by Simon Soanes
This is some code I wrote a little while back as an example O/R mapper.
-
Execute a Process and Fetch its Output
by James Crowley
Demonstrates how to redirect the output of a shell program (such as a batch file) so you can fetch the text it returns.
-
Sending email from ASP.NET
by Orcs Web
One of the most commonly performed operations that I see in web applications - aside from database actions - is sending email from code. This demonstrates how in ASP.NET.