The dll is a portable executable (PE) file format with .dll extension. It provides numerous advantages. Many development tools or IDE (Integrated Development Environment) presents to create or access dll file. This article explains how to access a C# class library, how to access a DLL in ASP.NET C#. Summary of the article:
- Creation of a DLL
- How to Access a DLL?
Creation of a DLL
At first create a ASP.NET Class Library Project. Suppose we will create a “MyCalculator.dll” and in this dll theae is Sum() method which will take two integer value as input and return the sum. Write appropritate code for that. Build the project. After build the DLL is created and it is located at bin or debug directory of the Project. Generally the name of a DLL is as like Project name.
How to Access a DLL?
With the help of Microsoft Visual Studio we can easily use an ASP.NET Class library project. The steps to access a DLL in ASP.NET application are given bellow:
If you have Microsoft Visual Studio installed, Start it and select New Project from the file menu. In the New Project dialog box:
- Open the Visual C# templates
- Select the template Windows Forms Application
- Set the project name to TestApplication
- Set the disk location to something like C:\TestProject
- Click Ok
New project will be created. Double click on “Form1.cs” and design the page as like:
Add the reference of “MyCalculator.dd”.For this from the Solution Explorer write click on Reference and click Add Reference. Click Browse tab and select “MyCalculator.dd” . Finally click on OK.
Write the following code under button1_Click event.
MyCalculator.Calculator oCalculator = new MyCalculator.Calculator();
label1.Text = oCalculator.Sum(Convert.ToInt16(textBox1.Text), Convert.ToInt16(textBox2.Text)).ToString();
Build the Application and run it. Provide two integer values and click ok. It will produce sum of the two integer values with the help of DLL.
In this way we can create DLL file and use it in our program or application.
If we can include a dll file in our projects successfully we can easily use all the functionalities of that dll without writing a single line of code. We just need to know which methods for which tasks and how to call them.