Thursday, June 20, 2013

How to use a DLL in ASP.NET page using Microsoft Visual Web Developer Express

So you've created a DLL assembly for shared code (perhaps using Microsoft Visual Basic Express or some other), and you want to use it on your website, accessing a public class from the DLL. This is how I did it in Microsoft Visual Web Developer 2010 Express edition...

STEP 1: Add a reference to the DLL to your website.

  1. In Solution Explorer, select your Web project.
  2. On the Website menu (for Web site projects) or the Project menu (for Web application projects), choose Add Reference. Alternatively, you can right-click the name of your Web project in Solution Explorer and then select Add Reference.
    The Add Reference dialogue box is displayed.
  3. Select the Browse tab.
  4. Browse to the folder that contains the assembly you want to reference, select the assembly, and then click OK.

    Adding a reference in this way ensures that all file dependencies (debug files, XML document files, and so on) are copied.

STEP 2: Use the public class from the DLL on you page

Use Imports to utilize the namespace from your DLL, then simply use Dim and New to instantiate a new object using a public class from the DLL. ie:

Imports MyDLLNameSpace

Dim myObject As New dllPublicClass 

If you just use the Dim statement Visual Web Developer should prompt you to add the Imports statement.


No comments:

Post a Comment