Imports

Last post 01-23-2008 8:26 AM by RabBell. 3 replies.

Sort Posts:

  • Imports

    01-18-2008, 6:48 AM
    • Member
      175 point Member
    • RabBell
    • Member since 08-21-2006, 2:28 PM
    • Posts 225

    This is a simple thing I seen written somewhere once but never had to use.

    If I'm adding the following to the top of all my page
     
    Imports System.IO

    There is somewhere I can add a bit of code that would include them all in one place so I wouldn't need to add them all in one place but I don't remember where that place is.

    Slightly confused by the fact my site is an ASP.Net AJAX site so I'm not used to the differences in the web.config file.

     

    Anyway is there somewhere I can add "Imports System.IO" that would mean adding it to each page would be unnecessary? 

  • Re: Imports

    01-18-2008, 9:03 AM
    • Member
      218 point Member
    • yonahw
    • Member since 06-07-2007, 12:02 PM
    • Posts 68

     I don't know if this is the best way to accomplish what you are doing but, you could create a base page which extends system.web.ui.page by inheriting it and add the imports to that.  You could then have all of your pages inherit from you base page instead of system.web.ui.page and it would automatically include any other imports you added.

  • Re: Imports

    01-18-2008, 9:25 AM
    Answer
    • Contributor
      3,070 point Contributor
    • r_nassabeh
    • Member since 01-11-2008, 10:14 AM
    • Shiraz, Iran
    • Posts 497

    Go to web.config, find the pages element. It should look like this:

     

    <pages>
                <namespaces>
                    <clear />
                    <add namespace="System" />
                    <add namespace="System.Collections" />
                    <add namespace="System.Collections.Specialized" />
                    <add namespace="System.Configuration" />
                    <add namespace="System.Text" />
                    <add namespace="System.Text.RegularExpressions" />
                    <add namespace="System.Web" />
                    <add namespace="System.Web.Caching" />
                    <add namespace="System.Web.SessionState" />
                    <add namespace="System.Web.Security" />
                    <add namespace="System.Web.Profile" />
                    <add namespace="System.Web.UI" />
                    <add namespace="System.Web.UI.WebControls" />
                    <add namespace="System.Web.UI.WebControls.WebParts" />
                    <add namespace="System.Web.UI.HtmlControls" />
    	</namespaces>
    </pages>
     It contains list of namespaces that are automatically added to each page. So what you need is just add System.IO to the list
    Reza Nassabeh


    Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
  • Re: Imports

    01-23-2008, 8:26 AM
    • Member
      175 point Member
    • RabBell
    • Member since 08-21-2006, 2:28 PM
    • Posts 225

    Thanks, worked great

    Put off a little at first cause AJAX Web Config files doesn't have that section at first, works though if you add it to the pages section

     

    thanks again
     

Page 1 of 1 (4 items)