Developer Tools

    Visual C# .NET Code Samples

    Language:
    English
    This set of code samples show how to work with the most essential components of the .NET Framework and accomplish the most common coding tasks in C#.
    • Note:There are multiple files available for this download.Once you click on the "Download" button, you will be prompted to select the files you need.
      Version:

      1.0

      File Name:

      CSharpSamples.EXE

      AttributeSample.exe

      CallbacksSample.exe

      CodeAccessSecuritySample.exe

      COMPlusComponentSample.exe

      CreatingAWindowsServiceSample.exe

      CustomApplicationFilesSample.exe

      DirectoryMonitorSample.exe

      DragDropSample.exe

      GDIPlusSample.exe

      ImagesInSqlServerSample.exe

      InteractingWithAWindowsServiceSample.exe

      MaskedEditControlSample.exe

      MultiFileAssembliesSample.exe

      PrintDocumentSample.exe

      ReflectionSample.exe

      ResourceFilesSample.exe

      SmtpMailSample.exe

      StringBuilderSample.exe

      SystemConfigurationFilesSample.exe

      SystemTraySample.exe

      WebClientSample.exe

      WebServiceSecuritySample.exe

      XMLTextReaderWriterSample.exe

      Date Published:

      7/7/2003

      File Size:

      558 KB

      137 KB

      127 KB

      124 KB

      135 KB

      133 KB

      140 KB

      124 KB

      151 KB

      138 KB

      122 KB

      129 KB

      139 KB

      117 KB

      128 KB

      129 KB

      128 KB

      118 KB

      139 KB

      127 KB

      127 KB

      123 KB

      161 KB

      129 KB

        The following C# samples are available for individual download at the bottom of this page. You can also download the entire set at once by clicking CSharpSamples.exe, also listed at the bottom of the page. Originally developed for Microsoft® Visual Studio® .NET 2002, these C# samples will also work in Visual Studio .NET 2003, which 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 .NET Framework classes provide explicit asynchronous support using the BeginXXXX and EndXXXX naming conventions and how you can leverage this 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 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.
    • Supported Operating System

      Windows 2000, Windows Server 2003, Windows XP

        • 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.
        1. Click the file you want to download from the list below.
        2. Do one of the following:
          • To start the installation immediately, click Open or Run this program from its current location.
          • To copy the download to your computer for installation at a later time, click Save or Save this program to disk.

    Popular downloads

    Loading your results, please wait...

    Free PC updates

    • Security patches
    • Software updates
    • Service packs
    • Hardware drivers

    Microsoft suggests

    Download free tools to build apps for Windows.
    Download free tools to build apps for Windows
    Develop apps that reach the entire family of Windows devices.
    Get started