LANGUAGES: C# | VB.NET
TECHNOLOGIES: VS .NET
Make VS .NET treat any file like a code-behind file.
By Ken McNamee
If you've been using Visual Studio .NET to create your ASP.NET pages, I'm sure you're familiar with the concept of "code-behind." Code-behind is the source-code file containing the class your .aspx page inherits from. VS .NET helps keep the Solution Explorer from getting too messy by displaying the code-behind file as a child of the .aspx file in the treeview. Also, if there is also an .resx resource file, it gets displayed as a child to the code-behind file. This is a nice feature that unfortunately you can't use for any other type of file because VS .NET decides which files get displayed as children.
For example, if you want to associate an XML file with an .aspx page as a child, you can't do it from within the VS .NET IDE. This is possible, however, by editing the project file manually (.csproj or .vbproj) in a plain text editor such as Notepad. At the bottom of the project file is a list of File elements with several attributes you can exploit. The key here is the DependentUpon attribute. If you want to associate a Menu.xml file with a Default.aspx page, here is the syntax you should use:
RelPath = "Menu.xml"
DependentUpon = "Default.aspx"
BuildAction = "None"
Now, save the file and reopen VS .NET. The Default.aspx file now has an "XML-behind" file.
Ken McNamee is a senior software engineer with RelayHealth Corp., a provider of secure, Web-based services for doctor-patient communication. Prior to this, he led a team of developers in rebuilding the Home Shopping Network's e-commerce site, HSN.com, to 100 percent ASP.NET with C#. E-mail Ken at mailto:[email protected].