WorldofASP.NET : ASP.NET Tutorial, Hosting, and Source Code
You are 1 of 6789 users

WorldofASP.NET >> ASPNET >> General ASPNET

Use C# and VB.NET in the same project

Use C# and VB.NET classes in the same ASP.NET application

Published Date : 15 Oct 2007

Author : Mark Smith
Language : VB.NET,C#
Platform : Wins,.NET
 
Technology : Visual Studio,ASP.NET
Views : 2277
Rating : (3 votes so far)
Email to a Friend | Print this Article | Add to Favourites | Report Error

Introduction

Whilst it isn't ideal to both mix C# and VB.NET languages in the same ASP.NET project, it is possible. The code still has to be separated and it can't be mixed at page level but you can create a class in each language and then use and reference them both from any page.

Main

Step 1

Create an App_Code folder if it doesn't already exist. Then, inside this folder create two other folders to hold each language type.

For example,

App_Code
  vbcode
  cscode

Step 2

Edit your web.config file and make sure the following section is added:

 <SYSTEM.WEB>  
         <COMPILATION>  
             <CODESUBDIRECTORIES>  
                 <ADD directoryName="vbcode" />  
                 <ADD directoryName="cscode" />  
             </CODESUBDIRECTORIES>  
         </COMPILATION>  
 </SYSTEM.WEB>  

Add each class to the relevant folder and you're done! You can now reference any of the classes in the standard manner and ASP.NET will do all of the compilation automatically for you.

Conclusion

Certain scenario's may exist where it's required to use .NET code that was written in two different languages. Fortunately, it is fairly easy to implement to implement this in your project by specifying the two languages in your web.config file and telling ASP.NET which code directories to use.



Other Related and Popular Articles :

Working with Master Pages and Basics of Master Pages
Why do you need master pages and how it can improve the maintenance of your website
Tips to Improve Your ASP.NET Web site performance
The article contains guidelines for improving your ASP.NET Web applications
Publish and create RSS Feeds easily on your ASP.NET websites
This article explains the concept of creating RSS feeds for your ASP.NET website with auto updating contents
Working with HttpWebRequest and HttpWebResponse in ASP.NET
This article explain how to use WebRequest and WebResponse in ASP.NET to grab contents and screen scrape
Sending Email in ASP.NET 1
This article explain how to send email in ASP.NET 1 either by using SMTP authentication or not

Author Profile : Mark Smith

Click here to view Author Profile


How would you rate the quality of this content?
Poor Excellent

Comments

#Reply
10 Nov 2007 8:42 by : Mark Smith

"can we have mixed code in same page?"
No

"can we have mixed pages (not only classes) in same app? (3 vb pages and 2 c# pages in the root of the app)"
Yes

"can a class use an instance from another class written in a different language?"
Yes

#can we have mixed code in same page?
08 Nov 2007 7:43 by : ramzi

hello
can we have mixed code in same page?
can we have mixed pages (not only classes) in same app? (3 vb pages and 2 c# pages in the root of the app)

can a class use an instance from another class written in a different language?
thanks

Leave New Comments


Article Content copyright by Mark Smith
Everything else Copyright © by WorldofASP.NET 2008
 
Announcements
Earn Cash by writing an article or review
For more info Click here







Legend : - Within 3 Days - Within 6 Days - Within 9 Days

Home | Add Resources | Sponsored Listings | Advertise with Us | Contact Us | SiteMap | Link To Us | Contact Us
© 2002-2008 Worldofasp.net ASP.NET Directory, Hosting and Tutorials | All rights reserved
Our Partners : ASP.NET Web Hosting | Windows Web Hosting | FREE ASP.NET CMS | Phone Card | PHP Directory | Bangkok Hotels |Calling Card