Click here to Skip to main content
6,595,444 members and growing! (20,163 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Beginner License: The Code Project Open License (CPOL)

Beginner's Guide to ASP.NET Application Folder

By Abhijit Jana

This Article Describe you about Asp.Net Application folder like App_Code,App_Theme, App_Data, etc..
C#, Windows, ASP.NET, Dev, Design
Posted:7 Dec 2008
Updated:23 Dec 2008
Views:26,372
Bookmarked:102 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
33 votes for this article.
Popularity: 6.64 Rating: 4.38 out of 5

1

2
4 votes, 12.1%
3
8 votes, 24.2%
4
21 votes, 63.6%
5

Table of Content 

Introduction

              First of all I would like to thanks Sean Ewington  for his article Beginner's Walk for Web Development , which gives me a great opportunity to write some article for Beginner's on ASP.Net Web Development at CodeProject . After writing articles on caching and View State for beginners , I have decided to write a article on Asp.Net Application folder for Beginner's. But I will be back on rest of  State management part . Like my others articles I believe this will also give you very good idea on Application Folder .  Please give your valuable suggestion and improvement area that I can incorporate with this article and also on my next articles.

Overview ASP.NET Application Folder

ASP.Net 2.0 uses file-based approach. It's means all class files, resource files, Data , Folder are maintain in a hierarchical way. If we are working with ASP.Net 2.0 , we can add files and folder from "Add Items" Options. If we look at a sample application  hierarchy , It will looks following figure.

beginn1.jpg

we can add as many as files and folder (as per our requirements ) with our solutions.  And it's doesn't need to recompile them each and every time when they are added. Its Asp.Net's  overhead to dynamically compiled them when required. So, what ASP.Net 2.0 does, it contain a defined folder structure, contains files (Classes, Images, Resources etc.. ), compile them dynamically and even we can access those files through out the application. ASP.Net Provides some special folder also to maintain files and resources. Let's see the advantages of using those folder .

Advantages of ASP.NET Application Folder 

Following are the main advantages of use of ASP.Net Application Folder

  • We can maintains resources ( Classes, Images, Code, Databases , Themes ) in a organized way, which give us to developed and maintain sites easily.
  • All  files and folder are accessible by  through the application.
  • We can add as many files as possible as per our requirements.
  • Files are compiles dynamically when required.

Different Types of Application Folders 

Asp.Net treats following Folder in a special way , those are

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

Details of Application Folder

Now , look at the use of those folder , I am starting from App_Code.

App_Code Folder :  

As name suggest, App_Code Folder store classes, typed data set etc. All the items that are store in App_code , are automatically accessible by through out the application. If we store any class files (like .cs or .vb ) its compile them automatically  . Its automatically create type data set from .Xsd file and create XML Web services proxy class from WSDL.  Let's have a look how we can use App_Code Folder.

We can add App_Code Folder , by  Solution File -> Right Click -> Add Asp.Net Folder -> App_Code. Now App_Code Folder is now added with your application.

beginn2.jpg

 

Note :- Try to Add one more App_Code Folder by using following steps. Opppps... No , App_Code folder is not available there. So , Asp.Net allows to add App_Code folder for once.

Now we can add new items like Class, text, xml files inside the App_Code folder or we can also add existing files.

beginn3.jpg

Let's have a look one example , that how its works . In the App_Code folder , I have added a class "MyCSharpClass.cs" .

beginn4.jpg

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

beginn5.jpg

Now, Try to access this class, from any where of you application. "MyCsharpClass" will be accessible  through out the application.

beginn6.gif

 If we want to store different class like .cs, .vb then what will happened. If we kept both .cs and .vb class it will give following compilation error.

beginn7.jpg

Because, All the classes contained in App_Code Folder are built into a single Assembly , It can't have different language in root level or even a child level folder in following way.

beginn8.jpg

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

beginn10.jpg

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

beginn9.jpg

Now , I am moving to our next Part that is Bin Folder .

Bin Folder:

Bin folder is used for keeping the assemblies inside it. we can access those as a reference from any where of our web application. Use of Bin folder comes to the picture if we use any class library with our web application. Suppose, we are creating a Class Library  "TestLib" , After build the library , we will get "TestLib.dll", Now Right Click on Solution file -> Add References -> Project , Select TestLib Project, Click on OK. Check the bin folder, its contain TestLib.Dll and TestLib.Pdb files.

beginn11.jpg

Assemblies in Bin folder do not need to registered . Asp.net recognize the presence of dll inside the Bin Folder . Keeping .pdb files inside bin folder helps us for debugging. Main limitation of storing assemblies in bin folder that , they are in scoped of Current Application . Therefore they cannot access any code outside of current web application. [Source]

Let's have a look on App_Data Folder

App_Data Folder :

App_Data Folder used as a "data storage" for the web application. It can store, .mdf, .mdb, XML, etc  files.  Its manage all of your application data in a centrally manner. It can be accessible from any where of your web application.  The real advantage is that any file you place in App_Data won't be downloadable.

We can add .mdf file into App_Data Folder , directly by "Add New Item" . From there we can create table, procedure, function without opening SQL Server.  Now if we want to add that data in our application we can easily use.

beginn12.jpg

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


beginn13.gif

So we can connect with "MyDB.mdf" file using this ConnectionString . Check the bellow example which I have used to read the Table data from "MyDB.Mdf" file.

beginn14.gif

 

App_Theme Folder : 

If you want to give your web sites a consistent looks then you need to design Themes for your web application. App_Themes folder contains your Themes . A Theme folder can contain two Folder, one for Css files and another for Skin files. When we will add "App_Theme" automatically a sub folder with name "Theme1" will be created. we can change the name of Theme folder as per our requirement.

beginn15.jpg

I will not cover how to create skin file or Css file in this article, my main concern is how to apply them. You can find the details of  Skin and Css over here .

Now we have to apply the theme  to the page, there are several way to do that, we can set the theme from "aspx" page at page directive in following way,

beginn16.jpg

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

App_Browser Folder :

App_Browser Folder contain 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 following location,

beginn17.jpg

If you want to change .browse file, just copy the file to App_Browser Directory and change it. You can create new Browser files by just click on "Add New Item " on App_Browser Folder

beginn18.jpg

As I already mention, Browser file is an configuration file, generally its look like this

beginn19.gif

For More information

App_WebReference :

AS name suggest, App_WebReference folder contain reference of any web services. If we added any web servies with our web application it will come automatically inside App_WebReference folder as in windows application if we added any ".dll" its comes under "Reference" Folder .

beginn20.jpg

ASP.Net Resources :

                  Before start about App_GlobalResource and App_LocalResoce, I would like to give small introduction of Asp.net Resource. If you are creating a sites for multinational company or a public web sites that can be accessible by all over the world,  you need to consider the best ways to address users in different cultures with different languages with different country.ASP.NET provides the infrastructure to create Web applications that automatically adjust formatting and languages according to user preferences using Resource files.  Main purpose of Resource files is "Localization" of web application.

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

  • Local Resource
  • Global Resource

App_LocalResource folder contain Local Resources files and App_GlobalResource Folder contain  Global Resources files.

App_LocalResources :

Local Resource :-  Local resources are specific to a single Web page and should be used for providing multilingual functionality  on a Web page.

               Local resources must be stored in an App_LocalResources 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_LocalResources subfolders in every folder.

Resource file name should be like <pageName>[.langauge].resx . some example of local resource files are, Mypage.aspx.ex.resx, Mypage.aspx.de.resx.   Default.aspx.resx is the base resource file to use if no other resource file does not match with user current culture.

if you want to create local resource for a page , open the design view of the page and then from "Tool Menu" -> "Generate Local Resource" . The you will see a resource file is automatically created on App_LocalResource Folder. 

beginn21.jpg

Following code showing you XML Code for the resource file. for changing Resource file we can change from xml  or Resource Editor also.

beginn22.gif

 If we changing any thing on the page  resource file will automatically updated. If want to test application for Local_Resource, Just create a copy of "Default2.aspx.resx" and renamed it to "default2.aspx.fr.resx ( for french ). Now for a test, I have changed the button tool tip  for French Resource to "French ToolTip". Now Change your IE setting and set "French as default Culture" from Tools -> Internet options -> Languages ,  Add French in the list and test the Application.

beginn23.jpg

 Test the Button Tool Tip and you can test it for other Language also. 

beginn24.jpg

 

App_GlobalResources :

Global resources can be read from any page or code that is in the Web site . Global resources must be stored in the App_GlobalResources folder at the root of the application. We should use App_GlobalResource folder when we need single resource from multiple web pages. we can  define Asp.net control properties by manually associating them with resources in global resource files.  you can add global resource file by right click on "App_GlobalResources" folder and click on "Add Items". Add .resx files as resource.

beginn25.jpg

We can access those resources by programmatically .by Resource.Resource Object.

e.g :

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();

 

Summary

 As I already told this article all about the use of all application folder that are available in asp.net. I hope I have describe them well. There are lots of thing to learn like how to design themes and Skin, Working with Resource files . I am giving some reference links that can help you for further study. Skins & Themes , Asp.Net Resources  .Please Read those link at least for Resources which is very important part for Asp.Net 2.0 . In future I can plan for writing an article for beginner's on Resources. But Not now.

Again Thanks for reading this article. Please don't forget to give your suggestion .

 

Reference 

Asp.Net Web Sites Layout

Asp.Net Resources

History

Written on  07-Dec-2008 

 

License

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

About the Author

Abhijit Jana


Member
Abhijit has done Master Degree in Computer Application from Heritage Institute of Technology (HIT-K) ,Kolkata, West Bengal, India . He is an interested, committed, creative Software professional having more than 2.8 years of solid experience in web-based and windows based solutions in Microsoft Technologies using .NET 2.0, .NET 3.0 , .NET 3.5, ASP.NET 2.0, ASP.NET 3.5 C# 2.0, AJAX, Silverlight, Web Services, MS SQL Server 2005, Exchange Server, Active Directory, and Dot Net Nuke (DNN),Win Forms, WinServices, WSS (Windows Sharepoint Server 3.0 ), WPF, WWF. He is also an MCP (Microsoft Certified Professional) and MCTS (Microsoft Certified Technology Specialist) on Web Development. He has good knowledge of Object Oriented Programming, 3-Tier Architecture and Design Patterns as well as good command over IIS (IIS 5.1,IIS 6.0, IIS 7.0) and deployment of Application on Live Production Environment . His hobbies, listing to music and Developing Own small Tools Utilities and Knowledge sharing.


Awards
CodeProject MVP 2009
Prize winner "Best ASP.NET article of Sep 2009
Prize winner "Best ASP.NET article of July 2009
Prize winner "Best ASP.NET article of June 2009"
Prize winner "Best ASP.NET article of January 2009"
Prize winner "Best ASP.NET article of November 2008"

Prize winner "Best ASP.NET article of October 2008"

Abhijit's CodeProject Guru :

Occupation: Software Developer
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 23 of 23 (Total in Forum: 23) (Refresh)FirstPrevNext
GeneralGreat! PinmemberBinzThomas5:13 7 Oct '09  
GeneralRe: Great! PinmvpAbhijit Jana23:59 7 Oct '09  
Generalhi!, Pinmemberchathucj9:19 24 Aug '09  
GeneralRe: hi!, PinmvpAbhijit Jana23:04 1 Oct '09  
GeneralGood article PinmemberDonsw8:55 12 Feb '09  
GeneralRe: Good article PinmvpAbhijit Jana19:24 12 Feb '09  
GeneralRe: Good article PinmemberDonsw2:42 13 Feb '09  
Generalcongrats on MVP status for 2009 PinmvpSacha Barber3:10 6 Jan '09  
GeneralRe: congrats on MVP status for 2009 PinmvpAbhijit Jana3:21 6 Jan '09  
GeneralRe: congrats on MVP status for 2009 PinmvpSacha Barber6:21 6 Jan '09  
GeneralRe: congrats on MVP status for 2009 PinmvpAbhijit Jana18:50 6 Jan '09  
GeneralRe: congrats on MVP status for 2009 PinmemberDr.Luiji0:01 17 Jan '09  
GeneralRe: congrats on MVP status for 2009 PinmvpAbhijit Jana2:01 17 Jan '09  
GeneralApp_Code is not available in Web Application Project PinmemberWin Myan5:54 23 Dec '08  
GeneralRe: App_Code is not available in Web Application Project PinmemberAbhijit Jana18:31 23 Dec '08  
GeneralCool buddy Pinmemberashu fouzdar1:56 10 Dec '08  
GeneralRe: Cool buddy PinmemberAbhijit Jana2:39 10 Dec '08  
GeneralRe: Cool buddy Pinmemberashu fouzdar3:15 10 Dec '08  
GeneralApp_Code a bad idea? PinmemberGurliGebis2:28 7 Dec '08  
GeneralRe: App_Code a bad idea? [modified] PinmemberAbhijit Jana2:43 7 Dec '08  
GeneralRe: App_Code a bad idea? Pinmembersibercyberia3:05 7 Dec '08  
GeneralRe: App_Code a bad idea? PinmemberAbhijit Jana3:09 7 Dec '08  
GeneralRe: App_Code a bad idea? Pinmemberthund3rstruck16:41 8 Dec '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Dec 2008
Editor:
Copyright 2008 by Abhijit Jana
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project