467,927 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,927 developers. It's quick & easy.

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
  • viewed: 1878
Share:
6 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
60 posts views Thread by Derrick Coetzee | last post: by
9 posts views Thread by zolli | last post: by
5 posts views Thread by David Mathog | last post: by
1 post views Thread by ya man | last post: by
14 posts views Thread by Jon Rea | last post: by
7 posts views Thread by Giancarlo Bassi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.