Sunday, January 27, 2013

How to add Class Library to ASP.NET WebSite

1. Create a new ASP.NET Website with Visual Studio. I have used Visual Studio 2010 and it generates some default files as shown in the figure.

2. To add the class library, right click on the projects root node in solution explorer and click add new project.

3. On the appearing window select Class Library, select the the path for the class library to be saved and type a suitable name for the library.

4. Once the library is created a default class will be create as Class1. Let's add a sample method to Class1 which simply returns a string.

5. Now right click on the class library and click on Build.

6. So far you have created the library successfully, now you need to reference the library to you'r website . Right click on the website name and click on Add Reference.

7. On the appearing window Select the library and click OK.

8. Expand the Bin directory in you'r website project and you'll see the .dll reference files of the class library in it.

9. Open the Default.aspx.cs file and type Class1 then you can add the reference to the library to you'r website as shown in the below image.

10. Create a new object from Class1 and call the "GetName()" method which returns the string.

11. finally build the whole project.

No comments:
Write comments
Recommended Posts × +