Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin



ASP.NET 2.0: Use VB.NET and C# within the App_Code folder

When I was creating my new blog site (this site your looking at), I chose to write it in C#. I had a problem with the App_Code folder because I had some code in VB.NET code and some C# code I needed to put in there. I didn't want to rewrite my VB.NET code in the App_Code folder just so I could write the rest of the code for the site in C#.

Luckily, the ASP.NET Team had already thought about just this kind of circumstance. They implemented a way to partition the App_Code folder into sub-folders, one for each set of code files written in the same programming language. Awesome, I didn't have to spend a couple hours converting code from VB.NET to C#!

Even if you don't use multiple different programming languages for your code files in the App_Code folder, you could use this feature to organize your sets of related code files into sub-folders.

Step 1: Add the following lines to the web.config

[code:xml]
<configuration>
    <system.web>
        <compilation>
            <codeSubDirectories>
                <add directoryName="VB_Code"/>
                <add directoryName="CS_Code"/>
            </codeSubDirectories>
        </compilation>
    </system.web>
</configuration>
[/code]

Step 2: Create a sub-folder in the App_Code folder for each language you want to support.
For Example:
/App_Code/VB_Code
/App_Code/CS_Code

Step 3: Place your VB.NET code in the VB_Code folder and place C# code in the CS_Code folder.

Currently rated 4.1 by 7 people

  • Currently 4.142857/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Thursday, March 30, 2006 9:39 PM
Permalink | Comments (14) | Post RSSRSS comment feed

Related posts

Comments

Vincent

Friday, April 07, 2006 7:19 PM

Vincent

Good explaination given for using both languages VB and C# in the appcode folder. along with clear documentation on how to write stuff in the web.config file. Steps format of document was very useful.
Thanks buddy

Jersey

Wednesday, May 03, 2006 8:50 PM

Jersey

Great! This is what I was looking for and it works!

Thank you very much.
Serna

PkingROch

Thursday, June 15, 2006 6:16 AM

PkingROch

Unfortunately, Remove is part of the schema in the documentation, but it won't compile...

Chris Pietschmann

Thursday, June 15, 2006 6:51 AM

Chris Pietschmann

Remove? What would you use Remove for with this? You don't even need to use Remove.

Ron Kincaid

Wednesday, June 21, 2006 2:35 PM

Ron Kincaid

Thanks! Timely, easy and very useful.

The Coder

Sunday, July 09, 2006 12:05 PM

The Coder

Good work! Just what I needed.

manisha

Saturday, July 15, 2006 4:13 AM

manisha

excellent and easy for understanding for us who are now studying the asp.net

vnguyen

Saturday, July 15, 2006 4:34 AM

vnguyen

Is there any way not to use App_Code at all? I migrate my project from 03 and it keeps separating some asp.net code files (.aspx.vb) from the aspx file and put in App_code. Same thing happened with my report files. Any suggestion?

mtran

Wednesday, August 16, 2006 7:39 AM

mtran

Thanks for the instructions how to setup for both languages.

All Aboard

Tuesday, October 03, 2006 6:31 AM

All Aboard

C'mon get aboard the love train!

Mehdi

Thursday, December 28, 2006 6:32 AM

Mehdi

I have a huge app_code folder with many sub-folders. When I make a change in one of the files in App-code folder, the build takes too long. It rebuids all the sub-folders in app_code. Is there a way to get it to build only the changed folder?

Thanks

faizer

Thursday, December 28, 2006 11:09 AM

faizer

Thanks a lot! It was a pain to find a way around this problem... But with your help it works now! Thanks again!!! Smile

Chris Pietschmann

Thursday, December 28, 2006 1:35 PM

Chris Pietschmann

Actually, the only solution to your problem is to pull out some or all of you classes in the App_Code and compile them into a DLL in the Bin folder. The App_Code folder isn’t really meant to contain large amounts of code.

Ajay

Thursday, December 28, 2006 11:16 PM

Ajay

This trick is useful. there are senarios when we need both in App_Code

Comments are closed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2008 Chris Pietschmann