- The App_Code folder does not allow multiple programming languages.
- still in a Web site project you can modify your folder structure and configuration settings to support multiple programming languages such as Visual Basic and C#. This allows ASP.NET to create multiple assemblies, one for each language.
- create simple website project.
- In the Website menu, click Add ASP.NET Folder, and then click App_Code.
- Right-click the App_Code folder and then click New Folder, name the new folder "CSCode".
- In "CSCode" folder, Add new item, choose the Class template, name the class "CSExample", select C# as the language, and click Add.
- In Solution Explorer double-click the CSExample.cs file to open it.
- Add the following code to the CSExample.cs file, overwriting the existing CSExample code that is already in the file.
public class CSExample { private string teamString; public CSExample() { TeamString = "C# Code"; } public string TeamString { get { return teamString; } set { teamString = value; } } }
- Create a folder and class for Visual Basic code by repeating steps 3-6 using the following values:
- New folder: VBCode
- New class file: VBExample
VBExample.vb
public class CSExample { Public Class VBExample Private teamStr As String Public Sub New() TeamString = "Visual Basic Code" End Sub Public Property TeamString() As String Get Return teamStr End Get Set(ByVal Value As String) teamStr = Value End Set End Property End Class }
Now the main part is Modifying the Web.config File
After creating separate subfolders for each programming language, you must change the Web site project configuration so that ASP.NET will compile the subfolders separately.To modify the Web.config file to support multiple programming languages
- In Solution Explorer, select the name of the Web site project.
- If your project does not already have a Web.config file, do the following:
- In the Website menu, click Add New Item.
- Choose Web Configuration File and then click Add.
- In the Website menu, click Add New Item.
- Double-click the Web.config file to open it.
- Modify the <compilation> section to include a <codeSubDirectories> node by copying the following section and pasting it as a child node of the <compilation> section:
Testing the classes
CSExample CSCode = new CSExample(); VBExample VBCode = new VBExample(); if (classLabel.Text == CSCode.TeamString.ToString()) { classLabel.Text = VBCode.TeamString.ToString(); } else { classLabel.Text = CSCode.TeamString.ToString(); }