Adding C# Web Form to VB Web Application

Posted on 2011-02-18
Last Modified: 2012-05-11
Is there any way to add a C# Web Form to an ASP.NET 4.0 Web Application that is written in VB.NET? I had an ASP.NET 2.0 *WEB SITE* that I recently converted to an ASP.NET 4.0 *WEB APPLICATION*. It was mostly written in VB.NET with a couple pages that had C# code behinds.

I've read the following article (the end section about mulitple languages):

But it does not seem to help for the following two reasons

1) When I converted my site to an application, it didn't seem to add an APP_CODE folder at all
2) I'm not looking to just write a simple class, I actually want to be able to add a WEB FORM with a C# code behind

When I try to add a new item and I select which type of item I want to add, I am only given to option to add a VISUAL BASIC web form.

I have a workaround right now. If I need a new web form with a C# code behind, I take one of my old C# web forms and just copy and paste the form and C# code behind into the project and then rename it and change the class name as well. Then i make my changes and do what I need to do. It seems to work, but I was just wondering if there was an easier way.

You might wonder why want to put C# forms in my VB app. I wrote my app in VB (not well versed in C# but I can read it). I have a programmer working for me that is much more efficient with C#. I don't really have the budget to spend weeks/months getting her up to speed with VB
Question by:citronsmurf
  • 3
  • 2
  • 2
  • +3
LVL 35

Expert Comment

by:Miguel Oz
ID: 34929772
You have to add this new folder to your web site (right click your website and click on add new folder, name the new folder  App_Code)
then you can put the C# files there.

Author Comment

ID: 34929843
There are no App_code folders for an web application. That's for web sites
LVL 35

Expert Comment

by:Miguel Oz
ID: 34931292
Note: For web app right click on your web app, click add, then new folder then name the new folder  App_Code (see attached picture)
You have to add this yourself. VS2010 will not do it for you when you created the web app. Once created add any web form or C# classes files.

Note: If you cannot create it your project may not be setup properly, just in case:  what kind of web app project is it? web app, mvc2 web app.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 34931394
How will this help me create new web forms with a C# codebehind file?
LVL 12

Expert Comment

ID: 34941606
mas_oz2003, you should not create an App_Code folder in a web application project.  This is because ASP.NET will ALWAYS compile all code in APP_CODE at runtime.  It would get compiled twice, once into the web application's main assembly and then again into a seperate assembly.  See

Expert Comment

ID: 34955648
You can convert the C# code to VB.NET with this tools:
And then you can add the VB.NET files to your web application.

Expert Comment

by:Anurag Agarwal
ID: 35008095
one more thing u may need to add in your web config

           <add directoryName="VBCode"/>
           <add directoryName="CSCode"/>


Refer to

codeSubDirectories Element for compilation

LVL 12

Expert Comment

ID: 35008370
anurag_onnet - that would make sense for a Web Project but the asker is building a Web Application.  There should not create an App_Code folder in a web application project (see my comment above)

Accepted Solution

citronsmurf earned 0 total points
ID: 35009223
I think I may have found a solution!

I personally haven't tried it, but my programmers (who code in C#, working on MY web app) have done this and say it works perfectly.

Instead of opening the project for the web app, they open Visual Studio and to go FILE->OPEN WEB SITE and then open their local, development site (http://local_development_ip). This actually allows them to open the web application AS a web site, keeps the source control intact, AND lets them chose if the want a vb o c# web page.

I'll try to replicate this when I get a chance and post my results here. I just figured I'd mention it because I've seen this question asked on other forums and no one seems to get an answer, at least not for WEB APPLICATIONS.

And not to be rude, but ust a suggestion for some of you posting here. I initially mentioned in my first post that this was a web application and referred to the "app_code" folder seperation solution and explained that it did not work for me because it didn't apply to web applications. However it seems that about 3 or 4 different times people posted the exact same solution despite other people replying to them, reminding them that that solution was only for SITES, not APPLICATIONS. Please remember to read the full post before replying with a solution in the future.
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35913532
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question