Understanding ASP.NET Application Folders
page 2 of 11
by SANJIT SIL
Feedback
Average Rating: 
Views (Total / Last 10 Days): 58778/ 77

App_Code

The App_Code folder is meant to store classes, .wsdl files, and typed datasets. Any of these items stored in this folder then is automatically available to all the pages in the solution. To create an APP_Code Folder, we can follow some steps. Right click on solution -> Select Add Folder -> App_Code Folder. After adding App_Code Folder, we can add files on it. Right Click on App_Code Folder will give the option to add different types of files which include class file, text file, dataset, report and class diagram. Let us add a class file named test.cs.

Listing 1

public class CurrentDateTime()
public string showDateTime()
{
return  System.DateTime.Now.ToString();
}

Now the class test.css is available to all the pages in the solution. To test the same an aspx page is created named test.aspx.

Listing 2

protected void Page_Load(object sender, EventArgs e)
    {
        CurrentDateTime cDT=new CurrentDateTime();
        string cTime = cDT.showDateTime();
        Response.Write(cTime.ToString());
    }

When we run test.aspx page, we will see that it uses the test.css class. So we do not need to compile the class file before it is in use. It should be noted that whatever we place in the App_Code Folder, would be complied into a single assembly. A class file written in C# can be used by the pages written in a different language (say in Visual Basic 2005). Even we can have class files written in different languages, but to work with them we have to configure in the following ways: We should add two different folders in App_Code Folder to place C# class and VB class separately. After that we should do required modification in web.config file.

Listing 3

<compilation>
<codeSubDirectories>
<add directoryName=”VBFolder”></add>
<add directoryName=”CSFolder”></add>
</compilation>

So it is important that the language specific subdirectory is registered in the web.config file; otherwise, all files underneath App_Code folder will be complied to a single assembly regardless of the folder they belong to. If a directory mentioned in the <codeSubDirectories> section does not exist, compilation error will arise.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 11:29:06 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search