Click here to Skip to main content
11,927,378 members (46,925 online)
Click here to Skip to main content
Add your own
alternative version


1 download
271 bookmarked

A Beginner's Guide to ASP.NET Application Folders

, 8 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
This article explains about ASP.NET application folders like App_Code, App_Theme and App_Data

Table of Contents


First of all I would like to thank Sean Ewington for his article Beginner's Walk - Web Development, which gives me a great opportunity to write an article for beginners on ASP.NET web development here on CodeProject. After writing articles on caching and view state for beginners, I have decided to write an article for beginners on the ASP.NET Application Folders. However, I will be back with another article on rest of state management. Like my other articles, I believe this will also give you very good idea on the Application Folders. Please give your valuable suggestions and ideas for improvement that I can incorporate into this article, as well as my future articles.

Overview - ASP.NET Application Folders

ASP.NET 2.0 uses a file-based approach. That means, all class files, resource files, data files and folders are maintained in a hierarchical structure. If we are working with ASP.NET 2.0, we can add files and folders using the Add Items option. If we look at a sample application hierarchy, it will look like the following figure.


We can add as many as files and folders as we like (according to our requirements) within our solutions,and it won't be necessary to recompile them each and every time they are added. It is ASP.NET'stask to dynamically compile them when required. So, what ASP.NET 2.0 does is, it uses a predefined folder structure containing the files (classes, images, resources, etc.), to compile them dynamically and we can access those files throughout the application. ASP.NET also provides special folders to maintain files and resources. Let's see the advantages of using these folders.

Advantages of ASP.NET Application Folders

Following are the main advantages of use of ASP.NET's Application Folders

  • We can maintain resources (classes, images, code, databases, themes) in an organized manner, which allows us to develop and maintain sites easily
  • All files and folders are accessible through the application
  • We can add as many files as required
  • Files are compiled dynamically when required

Different Types of Application Folder

ASP.NET treats the following folders in a special manner. They are:

  • App_Code
  • Bin
  • App_Data
  • App_Theme
  • App_Browser
  • App_WebReference
  • App_LocalResource
  • App_GlobalResource

Details of the Application Folders

Now, to look at the use of these folders, I am going to start from App_Code.

App_Code Folder

As its name suggests, the App_Code Folder stores classes, typed data sets, etc. All the items that are stored in App_Code are automatically accessible throughout the application. If we store any class files (like .cs or .vb) it compiles them automatically. It automatically creates type data sets from .xsd (XML schema) files, and creates XML web service proxy classes from WSDL.Let's have a look at how we can use the App_Code folder.

We can add an App_Code folder, by Solution File → right click → Add ASP.NET FolderApp_Code. The App_Code folder is now added to your application.


Note: Try to add one more App_Code folder by using the same steps. Oops... the App_Code folder is no longer available there. So, ASP.NET allows you to add an App_Code folder only once.

Now we can add new items like classes, text and xml files into the App_Code folder and we can also add existing files there.


Let's have a look at one example that shows how it works. Into the App_Code folder, I have added a class MyCSharpClass.cs.


In that class I have written a small spice of code for adding two numbers.


Now, Try to access this class, from any where in your application. You will see that MyCSharpClass is accessiblethroughout the application.


If we want to store different classes like .cs or .vb, then what will happen? If we kept both .cs and .vb classes in the same folder, it will give following compilation error:


This is because all the classes contained in the App_Code folder are built into a single assembly and it can't have different languages at root level, or even at child level folders in following manner:


We have a solution to overcome this problem. We have to create separate folders for C# and for VB or other classes.


Store class files separately in those folders and an configure the folder hierarchy in the web.config file.


Now I will move to our next part -the Bin folder.

Bin Folder

The Bin folder is used for keeping assemblies inside it. We can access those as a reference from anywhere of our web application. Use of Bin folder comes into the picture if we use any class library within our web application. Suppose we are creating a class library called TestLib. After building the library, we will get TestLib.dll. Now, right click on solution file → Add ReferencesProject, select the TestLib Project, click on OK. Check the Bin folder, it will contain TestLib.dll and TestLib.pdb files.


Assemblies in the Bin folder do not need to registered on the system, ASP.NET recognizes the presence of DLLs inside the Bin Folder. Keeping .pdb files inside Bin folder helps us in debugging. The main limitation of storing assemblies in the Bin folder is that their scope is limited to the current application. Therefore, they cannot access any code outside of current web application. [Source]

Next, let's have a look at App_Data folder

App_Data Folder

The App_Data folder is used as a data storage for the web application. It can store files such as .mdf, .mdb, and XML. It manages all of your application's data centrally. It is accessible from anywhere in your web application.The real advantage of the App_Data folder is that, any file you place there won't be downloadable.

We can add .mdf files to the App_Data folder directly by selecting Add New Item. From there we can a create table, procedure or function without opening SQL Server.Now if we want to add that data to our application, we can easily use it.


Now, look at the connection string that we need to write for accessing the App_Data folder's databases.


We can connect with MyDB.mdf database using this connection string. Check the example below, which I have used to read the table data from the MyDB.Mdf file.


App_Theme Folder

If you want to give your web sites a consistent look, then you need to design themes for your web application. The App_Themes folder contains all such themes. An App_Theme folder can contain two subfolders; one for CSS files and the other for skin files. When we add an App_Theme folder, a subfolder with name Theme1 will be automatically created. We can change the name of the theme folder as per our requirements.


I will not cover how to create skin files or CSS file in this article, my main concern here is how to apply them. You can easily find the details ofskins and CSS via Google.

Now that we have to apply the theme to the page, there are several way to do that. We could set the theme from aspx page using a page directive in following way:


While we are going to set themefrom aspx page, the list of themes available to us is as shown in the figure. We can set the theme from the code behind file also, and we can even change theme at runtime (using HttpHandler).

App_Browser Folder

The App_Browser folder contains browser information files (.browser files). These files are XML based files which are used to identify the browser and browser capabilities. You will find the browser files in the following location:


If you want to change a .browser file, just copy the file to the App_Browser folder and change it. You can create new browser files by just clicking on Add New Item of the App_Browser folder


As I already mentioned, a browser file is a configuration file, it generally looks like this:


See here for more information

App_WebReference Folder

As the name suggests, the App_WebReference folder contain references to any web services. If we added any web services with our web application, they go automatically into the App_WebReference folder, in the same way as in windows applications, if we added any DLLs, they would go under the Reference folder.


Resources Folders

Before starting on the App_GlobalResource and App_LocalResource folders, I would like to give a small introduction on ASP.NET resources. If you are, say, creating sites for a multinational company, or a public web sites that can be accessible from all over the world, you need to consider the best way to address users in different cultures and different countries in different languages. ASP.NET provides the infrastructure to create web applications that automatically adjust formatting and language according to the user's preferences, by using resource files.The main purpose of resource files is localization of the web application.

ASP.NET uses resource files to make supporting multiple languages simpler. Visual Studio 2005 can automatically generate XML resource files that contain text for your controls in different languages. When a user visits the sites, they can change the languages of the sites based on their preference. There are two type of resources:

  • Local resources
  • Global resources

The App_LocalResource folder contain local resource files and the App_GlobalResource folder contains global resource files.

App_LocalResource Folder

Local resources are specific to a single web page, and should be used for providing multilingual functionalityon a web page.

Local resources must be stored in the App_LocalResource subfolder of the folder containing the web page. Because you might have local resources for every page in your web application, you might have App_LocalResource subfolders in every folder.

Resource file names should be like <pageName>[.langauge].resx. Some examples of local resource files are, Mypage.aspx.ex.resx and Default.aspx.resx is the base resource file to use if no other resource file matches with the user's current culture.

If you want to create local resources for a page, open the design view of the page and then from Tool Menu select Generate Local Resource. You will then see that a resource file is automatically created in the corresponding App_LocalResource folder.


Note: Default2.aspx.resx is the resource file for Default2.aspx, and Others.aspx.resx is the resource file for Others.aspx. Both resource files are inside the App_LocalResource folder.

The following code shows you the XML code for the resource file. To change the resource file, we can either change the XMLdirectly or use the Resource Editor.


If we change anything on the page, the resource file will be automatically updated. If you want a test application for Local_Resource, just create a copy of Default2.aspx.resx and rename it to (for French resources). Now, as a test, I have changed the button's tool tipfor the French resource to "French ToolTip". Now change your web browser settings and set French as the default culture.

(For Internet Explorer, use Tools → Internet options → Languages, add French to the top of the list and test the application)


Test the button tool tip in this way, and you can test it for other languages also.


App_GlobalResource Folder

The App_GlobalResource folder can be read from any page or code that is anywhere in the web site. Global resources must be stored in the App_GlobalResource folder at the root of the application. We should use the App_GlobalResource folder when we need a single resource for multiple web pages. We candefine ASP.NET control properties by manually associating them with resources in global resource files.You can add a global resource file by right clicking on the App_GlobalResource folder and clicking on Add Items. Add .resx files as resources.


We can access these resources programmatically by using the Resource.Resource object.


Label1.Text = Resource.Resource.MyText

We can use the GetLocalResourceObject() and GetGlobalResourceObject() methods to access global resources, and then cast them to the correct type.

Label1.Text = GetLocalResourceObject("Label1.Text").ToString(); 


I have explained in this article all about the use of application folders that are available in ASP.NET. I hope I have described them well enough for you to understand. There is lots more to learn, like how to design themes and skins, and working with resource files. I am giving some reference links at the end, that can help you in further study.

Please read these links, at least the one on resources, which are a very important part of ASP.NET 2.0. In future I plan to write an article for beginners on ASP.NET Resources. But not now.

Thanks for reading, and please don't forget to give your suggestions!



  • Written on 07-Dec-2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abhijit Jana
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog :
Web Site :
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

You may also be interested in...

Comments and Discussions

SuggestionRedfly Pin
Christopher Andrews18-Nov-15 1:33
memberChristopher Andrews18-Nov-15 1:33 
SuggestionMy Vote 5 And One Suggestion Pin
Dharmesh .S. Patil6-Jul-15 19:56
professionalDharmesh .S. Patil6-Jul-15 19:56 
GeneralRe: My Vote 5 And One Suggestion Pin
Abhijit Jana14-Jul-15 5:20
mentorAbhijit Jana14-Jul-15 5:20 
QuestionApp_Resource file xml code Pin
swethavor7-Nov-14 5:55
memberswethavor7-Nov-14 5:55 
QuestionApp Code instance of classes Pin
rugbylover280115-Oct-14 0:27
memberrugbylover280115-Oct-14 0:27 web developer Pin
Muhammad Arbi Sajjan17-Oct-13 17:14
memberMuhammad Arbi Sajjan17-Oct-13 17:14 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun22-Apr-13 22:07
memberHumayun Kabir Mamun22-Apr-13 22:07 
GeneralMy vote of 5 Pin
csharpbd24-Mar-13 6:05
membercsharpbd24-Mar-13 6:05 
QuestionNice Article Pin
Vick_Web19-Mar-13 20:11
memberVick_Web19-Mar-13 20:11 
QuestionGood +4 Pin
Arunprasath Natarajan25-Feb-13 7:51
memberArunprasath Natarajan25-Feb-13 7:51 
GeneralMy vote of 5 Pin
shani_7591-Jan-13 21:02
membershani_7591-Jan-13 21:02 
GeneralMy vote of 5 Pin
Mani_Kish8-Oct-12 22:51
memberMani_Kish8-Oct-12 22:51 
GeneralGreat Job Pin
Pradeep Venishetti17-Sep-12 8:32
memberPradeep Venishetti17-Sep-12 8:32 
GeneralMy vote of 4 Pin
Ankit Kumar22-Aug-12 1:45
memberAnkit Kumar22-Aug-12 1:45 
GeneralMy vote of 5 Pin
sagar pathe18-May-12 2:31
membersagar pathe18-May-12 2:31 
GeneralMy vote of 5 Pin
Rahul Rajat Singh15-May-12 1:07
memberRahul Rajat Singh15-May-12 1:07 
QuestionGood work Pin
Chamila Ranasinghe26-Apr-12 19:02
memberChamila Ranasinghe26-Apr-12 19:02 
GeneralMy vote of 5 Pin
baihualin198330-Mar-12 22:15
memberbaihualin198330-Mar-12 22:15 
GeneralMy vote of 5 Pin
c27bharti3-Mar-12 0:55
memberc27bharti3-Mar-12 0:55 
GeneralMy vote of 5 Pin
Uday P.Singh24-Nov-11 10:17
memberUday P.Singh24-Nov-11 10:17 
GeneralMy vote of 5 Pin
Member 820348521-Nov-11 19:11
memberMember 820348521-Nov-11 19:11 
GeneralMy vote of 5 Pin
lovejun25-Oct-11 17:52
memberlovejun25-Oct-11 17:52 
GeneralMy vote of 5 Pin
Member 36821852-Mar-11 23:25
memberMember 36821852-Mar-11 23:25 
GeneralReally Good Article Pin
Member 30467096-Jan-11 2:03
memberMember 30467096-Jan-11 2:03 
GeneralRe: Really Good Article Pin
Hamyy427-Aug-12 22:54
memberHamyy427-Aug-12 22:54 
GeneralMy vote of 5 Pin
SChristmas29-Dec-10 5:53
memberSChristmas29-Dec-10 5:53 
GeneralMy vote of 5 Pin
prasad0219-Dec-10 22:53
memberprasad0219-Dec-10 22:53 
GeneralVery nice Pin
Bharat Gholami10-Dec-10 13:40
memberBharat Gholami10-Dec-10 13:40 
GeneralMy vote of 5 Pin
Petr Pechovic8-Dec-10 0:29
memberPetr Pechovic8-Dec-10 0:29 
GeneralMy vote of 4 Pin
saggy_8528-Sep-10 4:36
membersaggy_8528-Sep-10 4:36 
GeneralGreat! Pin
BinzThomas7-Oct-09 5:13
memberBinzThomas7-Oct-09 5:13 
GeneralRe: Great! Pin
Abhijit Jana7-Oct-09 23:59
mvpAbhijit Jana7-Oct-09 23:59 
Generalhi!, Pin
chathucj24-Aug-09 9:19
memberchathucj24-Aug-09 9:19 
GeneralRe: hi!, Pin
Abhijit Jana1-Oct-09 23:04
mvpAbhijit Jana1-Oct-09 23:04 
GeneralGood article Pin
Donsw12-Feb-09 8:55
memberDonsw12-Feb-09 8:55 
GeneralRe: Good article Pin
Abhijit Jana12-Feb-09 19:24
mvpAbhijit Jana12-Feb-09 19:24 
GeneralRe: Good article Pin
Donsw13-Feb-09 2:42
memberDonsw13-Feb-09 2:42 
Generalcongrats on MVP status for 2009 Pin
Sacha Barber6-Jan-09 3:10
mvpSacha Barber6-Jan-09 3:10 
GeneralRe: congrats on MVP status for 2009 Pin
Abhijit Jana6-Jan-09 3:21
mvpAbhijit Jana6-Jan-09 3:21 
GeneralRe: congrats on MVP status for 2009 Pin
Sacha Barber6-Jan-09 6:21
mvpSacha Barber6-Jan-09 6:21 
GeneralRe: congrats on MVP status for 2009 Pin
Abhijit Jana6-Jan-09 18:50
mvpAbhijit Jana6-Jan-09 18:50 
GeneralRe: congrats on MVP status for 2009 Pin
Dr.Luiji17-Jan-09 0:01
memberDr.Luiji17-Jan-09 0:01 
GeneralRe: congrats on MVP status for 2009 Pin
Abhijit Jana17-Jan-09 2:01
mvpAbhijit Jana17-Jan-09 2:01 
GeneralApp_Code is not available in Web Application Project Pin
Win Myan23-Dec-08 5:54
memberWin Myan23-Dec-08 5:54 
GeneralRe: App_Code is not available in Web Application Project Pin
Abhijit Jana23-Dec-08 18:31
memberAbhijit Jana23-Dec-08 18:31 
GeneralCool buddy Pin
ashu fouzdar10-Dec-08 1:56
memberashu fouzdar10-Dec-08 1:56 
GeneralRe: Cool buddy Pin
Abhijit Jana10-Dec-08 2:39
memberAbhijit Jana10-Dec-08 2:39 
GeneralRe: Cool buddy Pin
ashu fouzdar10-Dec-08 3:15
memberashu fouzdar10-Dec-08 3:15 
QuestionApp_Code a bad idea? Pin
GurliGebis7-Dec-08 2:28
memberGurliGebis7-Dec-08 2:28 
AnswerRe: App_Code a bad idea? [modified] Pin
Abhijit Jana7-Dec-08 2:43
memberAbhijit Jana7-Dec-08 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 8 Dec 2010
Article Copyright 2008 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid