This page includes a list of .NET programming examples, with source code.
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.
When 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 2003.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 2010There's no general-purpose unzip library that I found, for Javascript. This library provides that capability.
ZIP, or more accurately, the DEFLATE algorithm that is used by the ZIP format for compression, is known as a "bit shredding" approach, because it uses parts of bytes to store information. As a result of that, and of course the requirement to scan through text to look for duplicates, ZIP can be fairly CPU intensive. Some might say that implementing an unzip in javascript is foolhardy, for that reason.
Nevertheless, I did it. here it is.
Works in IE8 and Firefox 3.5/3.6. I didn't test in other browsers.
March 2010The 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 2003Don't use this. With .NET 2.0, Microsoft introduced the Stopwatch class which eliminated the need for this.
If you rely on System.DateTime to measure something like an RPC call or a web service invocation, you will be disappointed in the resolution of the tick. This utility class shows how to use PInvoke to call into the kernel32.dll and query the performance counters to get a hi-res timer in managed code.
December 2002Did 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