how do i reference a class that is in a different folder RRS feed


All replies

  • Follow steps below as required.

    1) To add a class in a dll from another project use the menu Project : Add existing item and then browse for the dll in the debug folder of another project

    2)  Once a class is added to a project you need to the beginning of the module a Import (basic) or using (c#) statement at the beginning of the module.  The statement uses the namespace (not the folder name) to indicate the location of the class.  For example

    Import System.Text.RegularExpression

    The above statement System, and Text are two namespaces.  RegularExpression is the class name. 


    Sunday, April 20, 2014 6:36 AM
  • if I have understood this correctly, you only need to access your class which happens to be in another folder. you really don't need to worry about this folder structure. before continuing, make sure that folder + class file is already added to the solution / project!

    now, simple add a using (open the class file & look at the namespace) like so where you would like to use this class:

    using ReplaceThisWithActualNamespace;

    hope this helps!

    Note: if the class is in another project, you will have to add reference to that project as well!

    Sunday, April 20, 2014 6:54 AM
  • sorry, I didn't give enough detail when I posted the question. I am using vs2013 and have been developing web sites with vb. I have now switched to c# and am trying to create a web application. When I create a separate folder for my class code .cs and then open default.cs and click ctl-space the folder namespace {} doesn't show up. the only namespace that I can pick is the root namespace for the project. then if I select that one, I don't have the option to drill down to the app_code namespace. I watched the video about the differences between web site and web app project. I don't see what I am doing wrong yet. however I downloaded the sample from the video and I can access the folder namespace where the class in the subfolder is located. i'm still diggning. i'm sure that i'm missing something simple. even if I try to add the subfolder namespace to my .cs with the namespace directive I get an error that it can't find the subfolder namespace.

    Sunday, April 20, 2014 3:54 PM
  • wow, I just figured out that if I add a folder AppCode instead of App_Code everything works fine and I can reference classes in there. There is something special about the folder name App_Code I guess.

    Sunday, April 20, 2014 4:18 PM
  • I feel so dumb sometimes. the real issue was not the folder name App_Code, the issue was that the class action in that folder was set to content instead of compile. I'm learning but slow. thanks for all the help. much appreciated.
    Sunday, April 20, 2014 4:36 PM