locked
accessing class file that is not in app_code folder RRS feed

  • Question

  • User339784538 posted

    i have a class file 'customer_class.cs'  inside the app_code folder , it is fine that i can run and accessing the class file inside this folder.

    now i am wondering if i put the class file outside app_code in somewhere else , how to write the code to access the customer_class.cs  file ? 

    thanks

    Friday, July 10, 2009 6:41 AM

Answers

All replies

  • User-796298121 posted

     I found a couple of links that may be of help to you.  They go on to say that you should either use the Web Application Project or to put your code into a DLL and then reference it.

    http://blogs.msdn.com/asgoyal/archive/2009/06/16/consuming-a-class-which-is-outside-of-app-code-folder-in-an-asp-net-website-project.aspx
    http://www.velocityreviews.com/forums/t556894-how-to-create-object-of-a-class-which-is-outside-of-appcode-folderin-aspnet-20-using-c.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 10, 2009 7:51 AM
  • User-744022866 posted

    if your class and your page, both have same name space.. .you are not required to use any thing extra.. if they are in diffrent namespace, you are required to import the name space .

    you can use using statment in c# or import statement in VB

    Friday, July 10, 2009 7:54 AM
  • User-1734134863 posted

    Hi,

    As far as I know, we have to put the class file into the App_Code folder if we use the website template in the Visual studio.  Please check the following words.

    App_Code is a new addition to the Website model in ASP.NET 2.0. It contains all standalone/helper .cs/.vb files and they are compiled automatially whenever you change anything in the files within. All classes in this folder are referenced automatically in the rest of the application. Also in the Website model, there are no default namespaces created automatically.

    If you still want to use the custom class which is not in the App_Code folder, I think the links which DrivenTooFar provides are great.

     

     

    Please feel free to let me know if I’ve misunderstood anything.

     

    Monday, July 13, 2009 12:24 AM
  • User339784538 posted

     I found a couple of links that may be of help to you.  They go on to say that you should either use the Web Application Project or to put your code into a DLL and then reference it.

    http://blogs.msdn.com/asgoyal/archive/2009/06/16/consuming-a-class-which-is-outside-of-app-code-folder-in-an-asp-net-website-project.aspx
    http://www.velocityreviews.com/forums/t556894-how-to-create-object-of-a-class-which-is-outside-of-appcode-folderin-aspnet-20-using-c.html

     

     

    i have try it out to compile it into DLL, it works .. thx

    Tuesday, July 14, 2009 8:54 AM
  • User339784538 posted

    Hi,

    As far as I know, we have to put the class file into the App_Code folder if we use the website template in the Visual studio.  Please check the following words.

    App_Code is a new addition to the Website model in ASP.NET 2.0. It contains all standalone/helper .cs/.vb files and they are compiled automatially whenever you change anything in the files within. All classes in this folder are referenced automatically in the rest of the application. Also in the Website model, there are no default namespaces created automatically.

    If you still want to use the custom class which is not in the App_Code folder, I think the links which DrivenTooFar provides are great.

     

     

    Please feel free to let me know if I’ve misunderstood anything.

     

     

     

    actually i have a main folder called 'main' and inside main folder there are sub folder 'main1' and 'main2', i place the class file inside the main2 -- app_code folder,  it works when i call the object class inside main2,  but when i try to call the object inside main1, it cannot work, why ?  i thought it can call out the class object which located in main2 -- app_code in any folder within this project, any idea ?

    Tuesday, July 14, 2009 9:12 AM
  • User339784538 posted

    Hi,

    As far as I know, we have to put the class file into the App_Code folder if we use the website template in the Visual studio.  Please check the following words.

    App_Code is a new addition to the Website model in ASP.NET 2.0. It contains all standalone/helper .cs/.vb files and they are compiled automatially whenever you change anything in the files within. All classes in this folder are referenced automatically in the rest of the application. Also in the Website model, there are no default namespaces created automatically.

    If you still want to use the custom class which is not in the App_Code folder, I think the links which DrivenTooFar provides are great.

     

     

    Please feel free to let me know if I’ve misunderstood anything.

     

     

     

    actually i have a main folder called 'main' and inside main folder there are sub folder 'main1' and 'main2', i place the class file inside the main2 -- app_code folder,  it works when i call the object class inside main2,  but when i try to call the object inside main1, it cannot work, why ?  i thought it can call out the class object which located in main2 -- app_code in any folder within this project, any idea ?

    Tuesday, July 14, 2009 9:14 AM
  • User188494879 posted

    But why would you want to create separate folders and move your class files over there. You are making yourself more confusing and making more work for yourself.

    You should either move your comman classes to your app_code folder or add another class library project to your current solution, add all your classes in there and add an reference to this to your web project.

    Tuesday, July 14, 2009 10:11 AM
  • User-153404742 posted

    Hi,

    As far as I know, we have to put the class file into the App_Code folder if we use the website template in the Visual studio.  Please check the following words.

    App_Code is a new addition to the Website model in ASP.NET 2.0. It contains all standalone/helper .cs/.vb files and they are compiled automatially whenever you change anything in the files within. All classes in this folder are referenced automatically in the rest of the application. Also in the Website model, there are no default namespaces created automatically.

    If you still want to use the custom class which is not in the App_Code folder, I think the links which DrivenTooFar provides are great.

     

     

    Please feel free to let me know if I’ve misunderstood anything.

     

     

     

    actually i have a main folder called 'main' and inside main folder there are sub folder 'main1' and 'main2', i place the class file inside the main2 -- app_code folder,  it works when i call the object class inside main2,  but when i try to call the object inside main1, it cannot work, why ?  i thought it can call out the class object which located in main2 -- app_code in any folder within this project, any idea ?

     

     

    If you have the class within a namespace say Main2Namespace and you have the class Main2 within this namespace, you can create an object like this:

     

     

    Dim ObjectName As Main2Namespace.Main2= New Main2Namespace.Main2()

    assuming that your folder structrue is as follows:

    App_Code -->Folder1-->Folder2-->Main2

    Tuesday, July 14, 2009 11:30 AM
  • User339784538 posted

    But why would you want to create separate folders and move your class files over there. You are making yourself more confusing and making more work for yourself.

    You should either move your comman classes to your app_code folder or add another class library project to your current solution, add all your classes in there and add an reference to this to your web project.

     

     

    ok. actually now im facing a problem whereby using logcls.dll  or  logcls.cs  also cannot work..

    here's my folder structure and the file list in the sales web project:

    sales->app_code folder
                -logcls.cs
          
             ->bin folder (here contains logcls.dll which i build the logcls solution project outside this      sales project, and then i add reference in here)

             ->order folder

             ->customer folder

     

    i try many ways to call the logcls in app_code folder but still cannot work..

    first way, in order folder, i call the logcls.cs (logcls cls=new logcls(); )  it let me create the object, thats fine...but when i goto customer folder, it don't..i thought app_code can be share by other folder since it is located in the sales (main folder) ..

    then i try the second way ..that is i use visual studio c# create a new project then add class and i just copy the code logcls.cs into this new project, then build solution and the dll file created.   After that, i goto sales webproject again and Add Reference the dll file and it automatically create a bin folder....and the result still the same, cannot call the object logcls.DLL in 'order' and 'customer' folder ...it comes out error like 'missing directive or namespace'..

    appreciate if u all can give both way solution, if not, at least the second way using DLL file, this is the method i prefer to use .. thx

     

     

     

     

    Wednesday, July 15, 2009 9:28 AM
  • User339784538 posted

     after some testing, i found that we must add reference in each of the folder , order and customer folder ,  i thought add reference in sales folder can work, but actually it can't..anyone know why?

     

    Thursday, July 16, 2009 8:03 AM