This page includes a list of .NET programming examples, with source code. Some of these are pretty old, but they remain here just for the sake of tradition! Some of them are newer. This page was last updated in May 2011.
This example shows how to consume XML obtained from an HTTP URL, within an ASP.NET page. The XML can be generated by "anything." In this example, an ASP.NET page consumes XML generated by one of (a) a locally hosted ASP.NET page, (b) a remotely-hosted ASP.NET page, or (c) a remotely-hosted JSP page. There was a prior version of this example that used the NASDAQ xml quote service, but apparently Nasdaq.com took that service offline (as of February 2004). In this example, the XML is generated from a query on a SQL Server database. The consuming ASP.NET page retrieves the XML, does a XSL Transform on it, then displays the resulting HTML. As an illustration, there is also an example that does the converse: in other words it's a JSP page that consumes XML from an ASPX.
This is a tiny command-line app, implemented in C#, that uses PCF in the MQ Classes for .NET, to inquire the queue names on a MQ QM. PCF is not supported in the MQ Classes for .NET for MQ v6.0, but it works anyway.
This is a simple WinForms explorer app that uses ADSI (via COM interop) to explore MQSeries. Starting with version 5.1? of IBM MQSeries, Mq exposes an ADSI provider. By this means, MQ objects, including queues, channels, and connections, are queryable and settable via ADSI. This app illustrates how to do it.
originally published April 2003, updated November 2004MQSeries ships with a "postcard" app that can be used to verify the installation of mqseries. This is an implementation of the MQ postcard app in C#, using the "MQ Classes for .NET" class libary, that originally shipped in MQ 5.3 CSD05 on Windows in October 2003. (The ma7p supportpac from IBM, published in February 2003, was the precursor of this class library). This postcard app interoperates with the postcard apps IBM has supplied (one written in Java, and another shipped only in binary form).
December 2005IBM's "MQ Classes for .NET" class library that ships with MQ includes undocumented PCF support. This example shows how to check for the existence of a queue, and create a queue, programmatically, using that PCF stuff.
December 2005When I build Regex's , I use a visual tool like Regex Designer - by Chris Sells.
But still, the testing of all of the combinations of input is not easy with this sort of visual tool. A generic regex test harness is useful. This is that tool. The output is in XML to allow scripting.
October 2003When I want to build a regex, it's nice to be able to dynamically test my trials and iterations. This is a tiny tool that helps out with that.
.NET lacks a built-in library to handle TAR archives. This library reads and writes tar archives and compressed (gzip'd) tar archives.
Tar is implemented in C#, in the source file Tar.cs. It requires .NET 3.5 at a minimum.
If you compile the Tar.cs module with the symbol "EXE" defined (/d:EXE on the csc.exe command line), then the result will be a console-based Tar application, much like the one shipped in Unix. Compiled this way, it has no dependencies on an external Tar dll.
If you compile the Tar.cs module with no EXE symbol defined, then the result will be a Tar dll, Ionic.Tar.dll, that provides a Tar class, that can then be used from other applications.
The supplied makefile builds both of these targets by default.
March 2010This library provides that capability a general-purpose unzip capability, for Javascript.
All general-purpose compression algorithms, including the DEFLATE algorithm that is used by the ZIP format for compression, deal with byte-oriented data. But Javascript and the XMLHttpRequest object have been traditionally optimized for handling text data. As a result of that, it's uncommon to see application-level compression and decompression, done in Javascript within the browser. Even so, it is possible, and even straightforward, if you know what to do.
What follows here is a demonstration that shows how to unpack and extract a zipfile, within the context of the browser. This isn't a general purpose unzip. In fact this unzip demonstration does not (and cannot) create filesystem files. It merely downloads a zipfile, peeks inside it, and displays the decompressed contents of that zip file in the browser window. What takes .25s on a desktop takes 3 seconds in a browser. For that reason, some might say that implementing an unzip in javascript is impractical. Maybe. In any case, here it is.
Works in IE8 and Firefox 3.5/3.6. I didn't test in other browsers.
March 2010This page demonstrates how to perform AES encryption from within javascript running in a browser page. It does RFC2898 key derivation (PBKDF2), and uses a salt and a variable keysize.
The encrypted texts can be decrypted with any AES encryption suite, including the RijndaelManaged class within .NET.
To get the source code and see how it's done, use "View Source".
Works in IE8 and Firefox 3.5/3.6. I didn't test in other browsers.
May 2011This page demonstrates how to perform DES and 3DES encryption from within javascript running in a browser page. It does RFC2898 key derivation (PBKDF2), and uses a salt and a variable keysize. It is similar to the AES encryption example (see above).
The encrypted texts can be decrypted with any DES encryption suite, including the Des class included in the .NET base class library.
To get the source code and see how it's done, use "View Source".
Works in IE8 and Firefox 3.5/3.6. I didn't test in other browsers.
May 2011The encryption support in .NET is pretty good. In .NET 2.0 Microsoft added support for AES and Rijndael algorithms. There are fully-managed implementations, as well as native implementations that are available via .NET wrappers.
It's easy to encrypt and decrypt in .NET, but a typical scenario involves encrypting in .NET and then decrypting in some other platform. One example is Javascript, for apps that run in a browser. Another example is a COM tool, that does not have access to .NET - say a VB6 application, or a Microsoft Excel spreadsheet.
SlowAES is a nice javascript library for performing AES encryption (not mine). It works well and is easy to use. But it doesn't include the complementary things you need for real-world encryption. It lacks an RFC 2898 PBKDF2 (key generator), for example.
The question becomes, how to integrate SlowAES and .NET's AES?
This example shows how. It shows:
Creating PDFs can be handy. Doing it from .NET seems like a broad need. Here are some examples for how to do it, using the itextsharp library.
published February 2006Didya ever wonder?... why DataGrids and other data-bound controls can use arrays of objects as data sources, but they display only public properties (not fields)? On the other hand, types generated by wsdl.exe generally export fields (not properties).
Suppose you want to invoke a web services method and display the result in a databound control. Or suppose you want to use XML Serialization, and display the result into a data-bound control. What are you gonna do?
But wait! There is a better way.
This sample shows a general solution for how to morph types with public fields - something you might get from a web service or from XML Serialization - into types with public properties - something a data-bound control can use. The approach is to dynamically generate a type, at runtime, and then convert the array of type1 into an array of type2, and use type2 as the DataSource for the data-bound control. eg,
Because this example uses System.CodeDom to generate the type, it also serves as a short illustration of how to use that nifty technology.
December 2002This console app sends a Wake-on-LAN Magic packet to the given MAC address.
October 2003This simple Windows Forms app loads an assembly from a local DLL or from a URL, then interrogates the assembly for its version, culture, codebase, location, etc; and then displays the results. It also itemizes the types available in the assembly.
April 2003Did you ever come upon the situation where you want to fill a DataSet from one database, but then update another database with the data? This simple example shows how to associate different connections to the Update command and the Select command for a single DataAdapter, thereby enabling this scenario. The example works with SQL Server, but could be modified to work with any 2 databases that share a common DataAdapter (eg, they are both accessed from the OledbDataAdapter).
You could also modify this sample to use 2 distinct DataAdapters.
February 2003