VS2013: How to use a VB/ASP.Net project in a C#/ASP.Net solution?

José Perez
José Perez used Ask the Experts™
I have a Visual Studio 2013 solution and there is 1 component I have not been able to translate to C# so my question is, can you tell how can I use an existing vb.net (VS2013) be used in an existing C#/ASP.Net Solution? I know in a solution you can mix both languages in different projects, but I dont know how to do it.

My solution is a website that first validate a user against Active Directory, If the user does not have a valid account in AD the solution will check the user against a local server. If a user exists in AD or LocalServer my page will take the username, password and have to pass it to another system called Documentum to run queries. This last one part is the VB.Net project.

Is this possible or can I do it? suppose I have in my page 2 textboxes (txtUsername and txtPassword) and one buton (btnValidateUser).
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
So you already have a C# project in a solution. Now to add the VB .Net code you can do the following.

In Solution Explorer select the solution node that is the top most node in that window. Then right click on it and select Add -> New Project. In the New Project window select on the left side select Visual Basic and on the right side select Class Library and give it a name and click OK. The code window opens for the just added VB project. You can add code to that new window and make sure that the functions you want to call are Public otherwise you will not be able to see them in the C# project. Once you have done this compile the project so that the code becomes available to the solution. Now go to the C# project and add a reference to the VB project by right clicking on the C# project name and selecting Add->Reference and in the new window select Project in the left panel and select the VB project on the right and then click on the OK button. In the C# code add a using statement to the VB project. Then all that is needed now is to instantiate the VB class as normal and use that reference to call the functions from the VB class.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial