472,807 Members | 5,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,807 software developers and data experts.

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.
Nov 15 '05 #1
6 2012
Dmitri Shvetsov wrote:
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.


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.
Nov 15 '05 #2
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" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
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.


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.

Nov 15 '05 #3
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" <ds*******@cox.net> wrote in message news:fWU0c.12379$id3.3055@fed1read01...
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" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
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.


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.

Nov 15 '05 #4
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]" <sd****@hotmail.com> wrote in message news:%2****************@tk2msftngp13.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" <ds*******@cox.net> wrote in message news:fWU0c.12379$id3.3055@fed1read01...
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" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
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.


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.

Nov 15 '05 #5
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.OnLoad()" line, and change : Page to : MyBasePage for every web page class
class AWebPage : MyBasePage
{
public override OnLoad(...) // override
{
base.OnLoad(); //calls MyBasePage.OnLoad()

// next, your specific code for this page
}

...
}

I hope it helps,

--
Sorin Dolha [MCAD, MCSD .NET]
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:evY0c.12425$id3.8678@fed1read01...
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]" <sd****@hotmail.com> wrote in message news:%2****************@tk2msftngp13.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" <ds*******@cox.net> wrote in message news:fWU0c.12379$id3.3055@fed1read01...
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" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
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.


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.

Nov 15 '05 #6
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]" <sd****@hotmail.com> wrote in message news:uA**************@TK2MSFTNGP09.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.OnLoad()" line, and change : Page to : MyBasePage for every web page class
class AWebPage : MyBasePage
{
public override OnLoad(...) // override
{
base.OnLoad(); //calls MyBasePage.OnLoad()

// next, your specific code for this page
}

...
}

I hope it helps,

--
Sorin Dolha [MCAD, MCSD .NET]
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:evY0c.12425$id3.8678@fed1read01...
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]" <sd****@hotmail.com> wrote in message news:%2****************@tk2msftngp13.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" <ds*******@cox.net> wrote in message news:fWU0c.12379$id3.3055@fed1read01...
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" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
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.


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.

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
9
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
1
by: Minh | last post by:
I've just installed VS.NET 2003 on my Athlon XP 1800+. However I couldn't get any project with STL includes to compile even if I create a new empty project (and added #include <string>). It gave me...
1
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
7
by: Giancarlo Bassi | last post by:
Please, what are here the 11 include files (found over the internet)? */mozzarella.c /* #include #include #include #include #include #include
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.