Download 23 C# Code Samples
The following C# samples are available for individual download below. You can also download the entire set at once by clicking CSharpSamples.exe. Originally developed for Microsoft Visual Studio .NET 2002, these C# samples will also work in Visual Studio .NET 2003. The samples will make any necessary conversions when you open the solution files. The samples include:
- Working with attributes in C# (AttributeSample.exe). Demonstrates the creation and use of custom attributes to extend and modify the behavior of code.
- Working with callbacks and delegates in C# (CallbacksSample.exe). Demonstrates the use of delegates, callbacks, and synchronous and asynchronous method invocation, including how Microsoft .NET Framework classes provide explicit asynchronous support using the BeginXXXX and EndXXXX naming conventions and how you can make use of this support in your own code.
- Code access security with C# (CodeAccessSecuritySample.exe). Demonstrates the use of .NET Framework Code Access Security, in which code can have permissions independent of the person executing the code.
- Creating a COM+ component with C# (COMPlusComponentSample.exe). Demonstrates how to create a COM+ component, what takes advantage of Transaction management service within COM+, then assign a strong name to the assembly, register the assembly in the Global Assembly Cache, and register the component with COM+.
- Creating a Windows Service with C# (CreatingAWindowsServiceSample.exe). Demonstrates how to create a Microsoft Windows Service that uses a FileSystemWatcher object to monitor a specific directory for changes in files.
- Working with Custom Application Files in C# (CustomApplicationFilesSample.exe). Demonstrates the use of custom application files to store application data in an XML format.
- Using a FileSystemWatcher Component in a Windows Form with C# (DirectoryMonitorSample.exe). Demonstrates how the FileSystemWatcher Class monitors the file system and raises events whenever a specified Directory or file within a specified Directory changes.
- Implementing Drag and Drop in Windows Forms with C# (DragDropSample.exe). A useful primer for developers coming from a Visual Basic background. Demonstrates the C# implementation of drag-and-drop operations in a Windows application, including the addition of sophisticated functionality like using context menus in a DragDrop event handler to give users a list of possible actions.
- Using GDI+ with C# (GDIPlusSample.exe). Contains code written in Visual C# .NET that uses GDI+ through the .NET Framework to create a Windows form that has a shaped appearance and a user control that displays a pie chart or bar graph based on supplied data.
- Read and Write Images to a SQL Server Database with C# (ImagesInSqlServerSample.exe). Demonstrates how to upload images into SQL Server by using standard HTML upload methods and then insert each image as a byte array into SQL Server.
- Interacting with a Windows Service with C# (InteractingWithAWindowsServiceSample.exe). A sample application that launches a Windows Form to allow the user to interact and manipulate the IIS Admin service on the local machine. The application works by placing an icon in the System Tray.
- Creating a Masked Edit Control using .NET Framework Regular Expressions with C# (MaskedEditControlSample.exe). Provides a basis for creating a textbox control that allows for input validation either as the user types (using a manually supplied regular expression) or after the control is left (using a designer supplied expression).
- Partitioning an Application into Multiple Assemblies with C# (MultiFileAssembliesSample.exe). Explains why it can be beneficial to create separate modules for an application download, and then demonstrates how to do so with C#.
- Using System Printing in C# Applications (PrintDocumentSample.exe). A sample application that shows how to print a formatted report from sample data stored in an XML file using the PrintDocument class in the System.Drawing.Printing namespace. Also illustrates the user selection of a destination printer and multiple print fonts.
- Using Reflection in C# (ReflectionSample.exe). Demonstrates how to gather information on various types included in any assembly by using the System.Reflection namespace and some main .NET base classes.
- Working with Resource Files in C# (ResourceFilesSample.exe). A sample application that demonstrates the use of resource files to localize application text based on the culture setting of a target machine.
- Sending Mail with SmtpMail and C# (SmtpMailSample.exe). Uses a simple Web form to demonstrate how to use the SmtpMail class in the .NET Framework.
- How to Perform String Manipulation with the StringBuilder and String Classes and C# (StringBuilderSample.exe). Demonstrates some basic string manipulation using both the StringBuilder and String classes.
- Application Configuration Using Configuration Files and the Registry Using C# (SystemConfigurationFilesSample.exe). A sample application that demonstrates methods of storing application settings by making use of both the system registry and application configuration files. Implements a custom configuration section to show how you can tailor these files to the specific needs of a particular application.
- Creating a System Tray Application with C# (SystemTraySample.exe). A sample Windows Form application that shows how you can allow users to monitor and interact with the IIS Admin service on the local machine.
- Using the System.Net.WebClient to Retrieve or Upload Data with C# (WebClientSample.exe). Demonstrates how to create a Windows Form that can use HTTP to download and save a resource from a specified URI, upload a resource to a specified URI, or read and write data through a stream object.
- Web Services Security with C# (WebServiceSecuritySample.exe). Examines how to use IIS to perform user authentication so that no changes to the Web Service are required in order to provide superior security.
- Reading and Writing XML Documents with the XmlTextReader and XmlTextWriter Class and C# (XMLTextReaderWriterSample.exe). Demonstrates how to retrieve information from an existing XML document and how to create a new XML document.
- Microsoft Visual Studio .NET 2002 or 2003
- Microsoft .NET Framework 1.0 or 1.1
Note: These C# samples were originally developed for Visual Studio .NET 2002. They will work in the 2003 version; Visual Studio .NET 2003 will convert the solution files as you open them.