Naveen P.N

Just another Blog to play with programming

ASP.NET Application Folders

leave a comment »

Hi in this article I will explain application folders in ASP.NET 2.0.You would have observed when you create ASP.NET Application you can add folders called application folders, these are special folders in asp.net each one has special purpose and meaning. ASP.NET 2.0 has the capability to automatically precompiled ASP.NET application whereas in 1.0 and 1.1 frameworks everything was compiling into DLL. This is not the case in ASP.NET 2.0 framework this is because of its defined folder structure Let us now examine the usage of each folder in detail.
There are 6 folders which can be added
a) \App_Code
b) \App_Data
c) \App_Themes
d) \App_GlobalResources
e) \App_localResources
f) \App_WebReferences
g) \App_Browsers

Hi in this article I will explain application folders in ASP.NET 2.0.You would have observed when you create ASP.NET Application you can add folders called application folders, these are special folders in asp.net each one has special purpose and meaning. ASP.NET 2.0 has the capability to automatically precompiled ASP.NET application whereas in 1.0 and 1.1 frameworks everything was compiling into DLL. This is not the case in ASP.NET 2.0 framework this is because of its defined folder structure Let us now examine the usage of each folder in detail.

There are 6 folders which can be added

a) \App_Code

b) \App_Data

c) \App_Themes

d) \App_GlobalResources

e) \App_localResources

f) \App_WebReferences

g) \App_Browsers

app1
\App_Code

The \App_Code folder is used to store classes, .wsdl (Web Service Description Language), and typed dataset The main use of \App_Code folder is any of the files used in this folder will be available to all the pages in the solutions. One nice thing whenever you place something inside the folder VS 2005 detects this and compiles it if is a class and creates XML web service proxy class (.wsdl).
Add the Calculator class into \App_Code folder, and we will refer this class in our solution

Calculator.cs

public class Calculator

{

public int add(int a, int b)

{

return (a + b);

}

public int sub(int a, int b)

{

return (a – b);

}

}

Default.aspx

protected void Page_Load(object sender, EventArgs e)

{

Calculator calc = new Calculator();

int a = calc.add(1, 2);

Label1.Text = a.ToString();

int b = calc.sub(2, 1);

Label2.Text = b.ToString();

}

We can add class file of both .vb and .cs but little trick as to be done, we have to configure web.config file.

<compilation>

<codeSubDirectories>

<add directoryName=”VB”></add>

<add directoryName=”CS”></add>

</codeSubDirectories>

</compilation>

\App_Data

This folder stores the data stores which is utilized by the application.It can contain Microsoft SQL Express files (.mdf files), Microsoft Access files (.mdb files), XML files, and more.

\App_Themes

Themes can provide common look and feel.It can contain .skin file ,css files , images.All these elements is called as theme

\App_Global Resources

Resource files are nothing but no executable text associated with the program,Typically resources are images,icons ,text and auxillary files.Resource files are  string tables that can serve as data dictionaries for your applications when these applications require changes to content based on things such as changes in culture. You can add Assembly Resource Files (.resx) to this folder, and they are dynamically compiled and made part of the solution for use by all your .aspx pages in the application.

Now let us create two resource files one for English and other for French.

  • English-Resource.resx :It is the default language file using American English

app2

  • French-Resource.resx: The second file is for the same text, but in Finnish Language

app3

When someone with a browser culture of fi-FI invokes the page, he sees the information that comes from this file (French-Resource.resx). Everyone else who comes to the site gets the information that comes from the other file (English-Resource.resx).

protected void Button1_Click(object sender, EventArgs e)

{

Label2.Text = Resources.Resource.Response + “” + TextBox1.Text;

}

By changing the language setting of Internet Explorer you can have the response in that language

app4

App_LocalResource

As \App_GlobalResources folder, is used application-wide. If you are not interested in constructing application-wide resources, then we should go for App_LocalResource whose resources can be used for a single .aspx page only.

\App_WebReference

The App_WebReferences folder is a new name for the previous Web References folder used in previous versions of ASP.NET. Now you can use the \App_WebReferences folder and have automatic access to the remote Web services referenced from your application.

\App_Browsers

The App_Browsers folder holds browser files, which are XML files used to describe characteristics and capabilities of these browsers. We can find a list of globally accessible browser files in the CONFIG\Browsers folder under the installation path. In addition, if you want to change any part of these default browser definition files, just copy the appropriate browser file from the Browsers folder to your application’s \App_Browsers folder and change the definition.

Download Code with Article>

Written by Naveen P.N

October 8, 2009 at 10:35 pm

Posted in ASP.NET

Leave a Reply