INCLUDE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dmitri Shvetsov

    INCLUDE

    Hi All,

    Does somebody know how can I include an external file into my C# source
    file?

    I need to insert the same strings (about 5-10) into about 75 different
    files, probably I will need to modify all these strings later, and I see it
    as a good idea to use an INSERT approach, but C# is not C++ and doesn't
    allow me just to insert some external file as I used to do. What's a command
    for that?

    Thanks,
    Dmitri.


  • C# Learner

    #2
    Re: INCLUDE

    Dmitri Shvetsov wrote:
    [color=blue]
    > Hi All,
    >
    > Does somebody know how can I include an external file into my C# source
    > file?
    >
    > I need to insert the same strings (about 5-10) into about 75 different
    > files, probably I will need to modify all these strings later, and I see it
    > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
    > allow me just to insert some external file as I used to do. What's a command
    > for that?
    >
    > Thanks,
    > Dmitri.[/color]

    Create a class in its own file, and add the string constants to it.

    e.g.:

    public sealed class StringConstants
    {
    // private constructor to stop it getting instantiated
    private StringConstants ()
    {
    }

    public const string One = "One";
    public const string Two = "Two";
    }

    Then later you can use StringConstants .One, etc.

    Comment

    • Dmitri Shvetsov

      #3
      Re: INCLUDE

      Not so easy. I need to do the same steps during ON_LOAD for every asp page.
      That's why I need to insert the same strings to compile them in different
      classes. If I could use an external file and define a static variables etc.,
      it would be a big difference.

      Dmitri.

      "C# Learner" <csharp@learner .here> wrote in message
      news:e6HWFVBAEH A.3256@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Dmitri Shvetsov wrote:
      >[color=green]
      > > Hi All,
      > >
      > > Does somebody know how can I include an external file into my C# source
      > > file?
      > >
      > > I need to insert the same strings (about 5-10) into about 75 different
      > > files, probably I will need to modify all these strings later, and I see[/color][/color]
      it[color=blue][color=green]
      > > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
      > > allow me just to insert some external file as I used to do. What's a[/color][/color]
      command[color=blue][color=green]
      > > for that?
      > >
      > > Thanks,
      > > Dmitri.[/color]
      >
      > Create a class in its own file, and add the string constants to it.
      >
      > e.g.:
      >
      > public sealed class StringConstants
      > {
      > // private constructor to stop it getting instantiated
      > private StringConstants ()
      > {
      > }
      >
      > public const string One = "One";
      > public const string Two = "Two";
      > }
      >
      > Then later you can use StringConstants .One, etc.[/color]


      Comment

      • Sorin Dolha [MCSD .NET]

        #4
        Re: INCLUDE

        Dmitri,

        Why don't you create a new class (let's call it MyPage) derived from Page, overload the OnLoad() method in MyPage, and then change the base type for every of your web pages' classes to MyPage instead of Page.

        This technique is a very common technique for adding common functionality to web pages (it's almost like the master template page concept which will be available in ASP .NET "Whidbey").

        --
        Sorin Dolha [MCAD, MCSD .NET]
        "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:fWU0c.1237 9$id3.3055@fed1 read01...
        Not so easy. I need to do the same steps during ON_LOAD for every asp page.
        That's why I need to insert the same strings to compile them in different
        classes. If I could use an external file and define a static variables etc.,
        it would be a big difference.

        Dmitri.

        "C# Learner" <csharp@learner .here> wrote in message
        news:e6HWFVBAEH A.3256@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Dmitri Shvetsov wrote:
        >[color=green]
        > > Hi All,
        > >
        > > Does somebody know how can I include an external file into my C# source
        > > file?
        > >
        > > I need to insert the same strings (about 5-10) into about 75 different
        > > files, probably I will need to modify all these strings later, and I see[/color][/color]
        it[color=blue][color=green]
        > > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
        > > allow me just to insert some external file as I used to do. What's a[/color][/color]
        command[color=blue][color=green]
        > > for that?
        > >
        > > Thanks,
        > > Dmitri.[/color]
        >
        > Create a class in its own file, and add the string constants to it.
        >
        > e.g.:
        >
        > public sealed class StringConstants
        > {
        > // private constructor to stop it getting instantiated
        > private StringConstants ()
        > {
        > }
        >
        > public const string One = "One";
        > public const string Two = "Two";
        > }
        >
        > Then later you can use StringConstants .One, etc.[/color]


        Comment

        • Dmitri Shvetsov

          #5
          Re: INCLUDE

          Hi,

          You know if it should be a very short code it would be fine, but it's only a part of the code and these few strings should be executed before the rest of the On_Load code that's different for each page and already done. So, I can't just derive the page from my own class. Although it could be a good idea and I will think about it. Maybe in this case we can avoid some extra code and just derive some common part of the code just sending the predefined constants to the constructors. Thanks.

          Dmitri.
          "Sorin Dolha [MCSD .NET]" <sdolha@hotmail .com> wrote in message news:%23QFOBrCA EHA.3400@tk2msf tngp13.phx.gbl. ..
          Dmitri,

          Why don't you create a new class (let's call it MyPage) derived from Page, overload the OnLoad() method in MyPage, and then change the base type for every of your web pages' classes to MyPage instead of Page.

          This technique is a very common technique for adding common functionality to web pages (it's almost like the master template page concept which will be available in ASP .NET "Whidbey").

          --
          Sorin Dolha [MCAD, MCSD .NET]
          "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:fWU0c.1237 9$id3.3055@fed1 read01...
          Not so easy. I need to do the same steps during ON_LOAD for every asp page.
          That's why I need to insert the same strings to compile them in different
          classes. If I could use an external file and define a static variables etc.,
          it would be a big difference.

          Dmitri.

          "C# Learner" <csharp@learner .here> wrote in message
          news:e6HWFVBAEH A.3256@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Dmitri Shvetsov wrote:
          >[color=green]
          > > Hi All,
          > >
          > > Does somebody know how can I include an external file into my C# source
          > > file?
          > >
          > > I need to insert the same strings (about 5-10) into about 75 different
          > > files, probably I will need to modify all these strings later, and I see[/color][/color]
          it[color=blue][color=green]
          > > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
          > > allow me just to insert some external file as I used to do. What's a[/color][/color]
          command[color=blue][color=green]
          > > for that?
          > >
          > > Thanks,
          > > Dmitri.[/color]
          >
          > Create a class in its own file, and add the string constants to it.
          >
          > e.g.:
          >
          > public sealed class StringConstants
          > {
          > // private constructor to stop it getting instantiated
          > private StringConstants ()
          > {
          > }
          >
          > public const string One = "One";
          > public const string Two = "Two";
          > }
          >
          > Then later you can use StringConstants .One, etc.[/color]


          Comment

          • Sorin Dolha [MCSD .NET]

            #6
            Re: INCLUDE

            It doesn't matter how much code you need to run. And you can use the method I have described even if you have different code on the web pages OnLoad methods by overriding OnLoad twice, once in the MyBasePage (template) class and once in every web page's class, like this:

            class MyBasePage : Page
            {
            public override OnLoad(...)
            {
            base.OnLoad(); // call the standard Page.OnLoad()

            // next, your lines which should execute on every page
            }

            ...
            }

            // repeat this for every page you currently have in the web site
            // basically you will only need to insert "base.OnLoa d()" line, and change : Page to : MyBasePage for every web page class
            class AWebPage : MyBasePage
            {
            public override OnLoad(...) // override
            {
            base.OnLoad(); //calls MyBasePage.OnLo ad()

            // next, your specific code for this page
            }

            ...
            }

            I hope it helps,

            --
            Sorin Dolha [MCAD, MCSD .NET]
            "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:evY0c.1242 5$id3.8678@fed1 read01...
            Hi,

            You know if it should be a very short code it would be fine, but it's only a part of the code and these few strings should be executed before the rest of the On_Load code that's different for each page and already done. So, I can't just derive the page from my own class. Although it could be a good idea and I will think about it. Maybe in this case we can avoid some extra code and just derive some common part of the code just sending the predefined constants to the constructors. Thanks.

            Dmitri.
            "Sorin Dolha [MCSD .NET]" <sdolha@hotmail .com> wrote in message news:%23QFOBrCA EHA.3400@tk2msf tngp13.phx.gbl. ..
            Dmitri,

            Why don't you create a new class (let's call it MyPage) derived from Page, overload the OnLoad() method in MyPage, and then change the base type for every of your web pages' classes to MyPage instead of Page.

            This technique is a very common technique for adding common functionality to web pages (it's almost like the master template page concept which will be available in ASP .NET "Whidbey").

            --
            Sorin Dolha [MCAD, MCSD .NET]
            "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:fWU0c.1237 9$id3.3055@fed1 read01...
            Not so easy. I need to do the same steps during ON_LOAD for every asp page.
            That's why I need to insert the same strings to compile them in different
            classes. If I could use an external file and define a static variables etc.,
            it would be a big difference.

            Dmitri.

            "C# Learner" <csharp@learner .here> wrote in message
            news:e6HWFVBAEH A.3256@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Dmitri Shvetsov wrote:
            >[color=green]
            > > Hi All,
            > >
            > > Does somebody know how can I include an external file into my C# source
            > > file?
            > >
            > > I need to insert the same strings (about 5-10) into about 75 different
            > > files, probably I will need to modify all these strings later, and I see[/color][/color]
            it[color=blue][color=green]
            > > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
            > > allow me just to insert some external file as I used to do. What's a[/color][/color]
            command[color=blue][color=green]
            > > for that?
            > >
            > > Thanks,
            > > Dmitri.[/color]
            >
            > Create a class in its own file, and add the string constants to it.
            >
            > e.g.:
            >
            > public sealed class StringConstants
            > {
            > // private constructor to stop it getting instantiated
            > private StringConstants ()
            > {
            > }
            >
            > public const string One = "One";
            > public const string Two = "Two";
            > }
            >
            > Then later you can use StringConstants .One, etc.[/color]


            Comment

            • Dmitri Shvetsov

              #7
              Re: INCLUDE

              O, yeah, it really helps, thanks a lot!

              I think that the question is closed. It's very bad that we can't import an external file as an additional code, but using this inheritance can help to solve this problem.

              Dmitri.
              "Sorin Dolha [MCSD .NET]" <sdolha@hotmail .com> wrote in message news:uAlVi0IAEH A.3804@TK2MSFTN GP09.phx.gbl...
              It doesn't matter how much code you need to run. And you can use the method I have described even if you have different code on the web pages OnLoad methods by overriding OnLoad twice, once in the MyBasePage (template) class and once in every web page's class, like this:

              class MyBasePage : Page
              {
              public override OnLoad(...)
              {
              base.OnLoad(); // call the standard Page.OnLoad()

              // next, your lines which should execute on every page
              }

              ...
              }

              // repeat this for every page you currently have in the web site
              // basically you will only need to insert "base.OnLoa d()" line, and change : Page to : MyBasePage for every web page class
              class AWebPage : MyBasePage
              {
              public override OnLoad(...) // override
              {
              base.OnLoad(); //calls MyBasePage.OnLo ad()

              // next, your specific code for this page
              }

              ...
              }

              I hope it helps,

              --
              Sorin Dolha [MCAD, MCSD .NET]
              "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:evY0c.1242 5$id3.8678@fed1 read01...
              Hi,

              You know if it should be a very short code it would be fine, but it's only a part of the code and these few strings should be executed before the rest of the On_Load code that's different for each page and already done. So, I can't just derive the page from my own class. Although it could be a good idea and I will think about it. Maybe in this case we can avoid some extra code and just derive some common part of the code just sending the predefined constants to the constructors. Thanks.

              Dmitri.
              "Sorin Dolha [MCSD .NET]" <sdolha@hotmail .com> wrote in message news:%23QFOBrCA EHA.3400@tk2msf tngp13.phx.gbl. ..
              Dmitri,

              Why don't you create a new class (let's call it MyPage) derived from Page, overload the OnLoad() method in MyPage, and then change the base type for every of your web pages' classes to MyPage instead of Page.

              This technique is a very common technique for adding common functionality to web pages (it's almost like the master template page concept which will be available in ASP .NET "Whidbey").

              --
              Sorin Dolha [MCAD, MCSD .NET]
              "Dmitri Shvetsov" <dshvetsov@cox. net> wrote in message news:fWU0c.1237 9$id3.3055@fed1 read01...
              Not so easy. I need to do the same steps during ON_LOAD for every asp page.
              That's why I need to insert the same strings to compile them in different
              classes. If I could use an external file and define a static variables etc.,
              it would be a big difference.

              Dmitri.

              "C# Learner" <csharp@learner .here> wrote in message
              news:e6HWFVBAEH A.3256@TK2MSFTN GP09.phx.gbl...[color=blue]
              > Dmitri Shvetsov wrote:
              >[color=green]
              > > Hi All,
              > >
              > > Does somebody know how can I include an external file into my C# source
              > > file?
              > >
              > > I need to insert the same strings (about 5-10) into about 75 different
              > > files, probably I will need to modify all these strings later, and I see[/color][/color]
              it[color=blue][color=green]
              > > as a good idea to use an INSERT approach, but C# is not C++ and doesn't
              > > allow me just to insert some external file as I used to do. What's a[/color][/color]
              command[color=blue][color=green]
              > > for that?
              > >
              > > Thanks,
              > > Dmitri.[/color]
              >
              > Create a class in its own file, and add the string constants to it.
              >
              > e.g.:
              >
              > public sealed class StringConstants
              > {
              > // private constructor to stop it getting instantiated
              > private StringConstants ()
              > {
              > }
              >
              > public const string One = "One";
              > public const string Two = "Two";
              > }
              >
              > Then later you can use StringConstants .One, etc.[/color]


              Comment

              Working...