tags:

views:

632

answers:

4

In the past, I have not really used namespaces, but in this project I am using SourceSafe which requires a project, which puts everything in namespaces...

In the past, I have just been able to make a public static class in the App_Code folder and access it frorm anywhere in my application, but now I cant seem to do that.

For example, my default.aspx.cs looks like this:

namespace Personnel_Database
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
              utils.someFunction();//this does not work

and my utils.cs class looks like this:

namespace Personnel_Database.App_Code
{
    public static class utils
    {

How can I have it so I can call util.someMethod() inside of my default? Am I wrong assuming it is a namespace problem? I just want utils.cs to be available globally inside namespace Personnel_Database

+1  A: 

Either you include the namespace with a using directive:

using Personnel_Database.App_Code;
// now you can use everything that is inside the Personnel_Database.App_Code namespace
namespace Personnel_Database
{
  ...

Or you use the fully quallified name of the utils class (including its namespace), e.g:

  protected void Page_Load(object sender, EventArgs e)
  {
    Personnel_Database.App_Code.utils.someFunction();
    ...
M4N
A: 

You just need to add:

 using Personnel_Database.App_Code;

to the top of your code-behind file. If you need access to it in the markup you can import it using:

 <%@ Import Namespace="Personnel_Database.App_Code" %>
tvanfosson
A: 

You need a using statement in the Personnel_Database Personnel_Database class file, i.e.

using Personnel_Database.App_Code;

Google/MSDN for the using statement.

ng5000
A: 

I was mistaken, if I insteada make the Utils class:

namespace Personnel_Database
{
    public static class utils    
    {

It does work, buut does not show in intellisense, how can I get it to do that?

naspinski
If you go this route -- and I don't necessarily recommend it since namespaces do add value in ordering your code -- you might also want to change the default namespace in your project properties so that new classes created in the project get your preferred namespace as the default.
tvanfosson