开发者

Where can I put my source files?

开发者 https://www.devze.com 2022-12-25 01:00 出处:网络
I am developing a web form using Vi开发者_如何学JAVAsual Web Developer Currently I have class source files in the same directory as the web form, or in the App_Code folder. I\'d like to organise the f

I am developing a web form using Vi开发者_如何学JAVAsual Web Developer Currently I have class source files in the same directory as the web form, or in the App_Code folder. I'd like to organise the files into folders within the web form folder, but I can't find a way of adding a reference to the folders, and they don't seem to be being picked up automatically. These are files that are under constant development.

What is the asp.net/c#'s equivalent concept to c++'s #include?

This is a Web Site rather than a Web Application


I'd suggest taking these out into a separate class library project and you can then reference this DLL in your web project. You would then add a 'using' statement at the top of your web form code to include this reference.


In a C# file (foo.cs), you would use:

using MyProjectsDefaultNamespace.Folder1.Folder2

In an aspx or ascx file, you would use:

<%@ Import Namespace="MyProjectsDefaultNamespace.Folder1.Folder2" %>


Never really thought of doing this, but i guess i would do this as follows. A folder represents a namespace. So where it says inherits="Project.PageName" in your PageName.aspx file, it should state inherits="Project.Folder.Folder.PageName". You also have to change the namespace in your PageName.aspx.designer.cs and PageName.aspx.cs files.

EDIT: For ASP.Net website simply adjust your CodeFile attribute:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Folder/Folder/Default.aspx.cs" Inherits="_Default" %>


Its not clear if you mean the codebehind .aspx.cs file or a standalone .cs class file.

You can't have .cs files loose in your main folder. It has to be in the app_code folder (or in a class library if you were doing a WAP).

Your .aspx.cs files are paired up with your .aspx file. I wouldn't recommend trying to move these files away if thats what you are trying to do.

The top level namespace that contains _Default or any code that doesnt appear to have a namespace is ASP. This is generally hidden within Visual Studio. So its true name is ASP._Default


And the answer is, obtained from looking into the other answers thanks:

Organise the files into folders within the App_Code folder, they will automatically be included.


  • Right click on project in solution explore
  • Go to Add> Add ASP.NET Folder > App_Code
  • Then add your files/folder structure there

BUT, be warned of what you put in there. Please refer to:

http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html

In the properties of the source file(s), you might want to set the "Build Action" property to "Compile"

0

精彩评论

暂无评论...
验证码 换一张
取 消