473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Default values for user settings

Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Thanks for any help,

Jun 27 '08 #1
8 2024
Personally, I'd simply use %windir%\NOTEPAD.EXE as the default, and
use Environment.ExpandEnvironmentVariables() to do the expansion on-
demand.

Marc
Jun 27 '08 #2
I don't thinkg the ApplicationSettings class is able to evaluate the
expression and return the correct value.

Then only way I see that you can accomplish something like what you want is
to hack the "Settings.Designer" class and hardcode the changes so that it
would look something like this:

[global::System.Configuration.UserScopedSettingAttr ibute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]
public string TextEditor
{
get
{
return System.Environment.GetEnvironmentVariable("windir" ) + "\\" +
((string)(this["TextEditor"]));
}
set
{
this["TextEditor"] = value;
}
}

I think thissolution is reeeeeeeeeally cheese. For consistnecy, I guess you
can add code to the "set" accsesor so that get and set are consistent (the
set and get return the same type of string with "windir" as the prefixed
path).

Keep in mind that the designer will overwrite everything every time you make
a change so you will have to constantly remember to update the file.

I would't recommend going this way but if you have no other choose well
there is an option.....


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48**********************@roadrunner.com...
Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I
realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Thanks for any help,



Jun 27 '08 #3
Thanks Marc for the response. I tried %windir%\notepad.exe however, I'm a
little confused. I still can't get it to return the actual Windows
directory instead of the text "%windir%". I was hoping there was a way to
enter a default setting using the designer which would execute at run-time.
I guess there's no way to do this other than assigning the values
programmatically.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:0f**********************************@x35g2000 hsb.googlegroups.com...
Personally, I'd simply use %windir%\NOTEPAD.EXE as the default, and
use Environment.ExpandEnvironmentVariables() to do the expansion on-
demand.

Marc

Jun 27 '08 #4
Thanks, but what a pain! I thought this would be such an easy thing to do,
but it doesn't seem to be the case. What would you suggest instead of the
settings class? Is there an easier way to manage user settings for a small
project which is what I'm working on?

"Rene" <a@b.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I don't thinkg the ApplicationSettings class is able to evaluate the
expression and return the correct value.

Then only way I see that you can accomplish something like what you want
is to hack the "Settings.Designer" class and hardcode the changes so that
it would look something like this:

[global::System.Configuration.UserScopedSettingAttr ibute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]
public string TextEditor
{
get
{
return System.Environment.GetEnvironmentVariable("windir" ) + "\\" +
((string)(this["TextEditor"]));
}
set
{
this["TextEditor"] = value;
}
}

I think thissolution is reeeeeeeeeally cheese. For consistnecy, I guess
you can add code to the "set" accsesor so that get and set are consistent
(the set and get return the same type of string with "windir" as the
prefixed path).

Keep in mind that the designer will overwrite everything every time you
make a change so you will have to constantly remember to update the file.

I would't recommend going this way but if you have no other choose well
there is an option.....


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48**********************@roadrunner.com...
>Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I
realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Thanks for any help,




Jun 27 '08 #5
Clarks Computing wrote:
Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say
I create a user setting called TextEditor in the settings designer. I
realize that I can type a string value such as NOTEPAD.EXE in the
Value column. However, what if I want to make the default value
something like the following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?
Make the default a special string ("__DEFAULT__" or maybe just ""), test for
it and substitute your dynamic value.

Settings can't be dynamic, they are stored in an xml file.
>
Thanks for any help,

Jun 27 '08 #6
Now that I am taking a second look at your problem, what about creating a
"partial class Settings"?

This is actually built in .Net, all you do is go to the settings designer
and click on the "View Code" toolbar button. This will automatically
generate the class for you (it can't get any easier)!

Then you can make the changes in the automatically generated class so that
it looks something like the following:

internal sealed partial class Settings
{
public Settings()
{
this.SettingsLoaded += this.Settings_SettingsLoaded;
}

private void Settings_SettingsLoaded(object sender,
System.Configuration.SettingsLoadedEventArgs e)
{
if(this.TextEditor == string.Empty)
this.TextEditor =
System.Environment.ExpandEnvironmentVariables(@"%w indir%\NOTEPAD.EXE");
}
}

That's it, if the value of "TextEditor" is empty (this should be your
default value) then you set it to the proper value. After that, the value
should be hardcoded to the exact path.

Does this help you?


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48***********************@roadrunner.com...
Thanks, but what a pain! I thought this would be such an easy thing to
do, but it doesn't seem to be the case. What would you suggest instead of
the settings class? Is there an easier way to manage user settings for a
small project which is what I'm working on?

"Rene" <a@b.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I don't thinkg the ApplicationSettings class is able to evaluate the
expression and return the correct value.

Then only way I see that you can accomplish something like what you want
is to hack the "Settings.Designer" class and hardcode the changes so that
it would look something like this:

[global::System.Configuration.UserScopedSettingAttr ibute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]
public string TextEditor
{
get
{
return System.Environment.GetEnvironmentVariable("windir" ) + "\\"
+ ((string)(this["TextEditor"]));
}
set
{
this["TextEditor"] = value;
}
}

I think thissolution is reeeeeeeeeally cheese. For consistnecy, I guess
you can add code to the "set" accsesor so that get and set are consistent
(the set and get return the same type of string with "windir" as the
prefixed path).

Keep in mind that the designer will overwrite everything every time you
make a change so you will have to constantly remember to update the file.

I would't recommend going this way but if you have no other choose well
there is an option.....


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48**********************@roadrunner.com...
>>Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I
realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Thanks for any help,




Jun 27 '08 #7
That's exactly what I was looking for! That did the trick. Thank you so
much.

"Rene" <a@b.comwrote in message
news:em**************@TK2MSFTNGP06.phx.gbl...
Now that I am taking a second look at your problem, what about creating a
"partial class Settings"?

This is actually built in .Net, all you do is go to the settings designer
and click on the "View Code" toolbar button. This will automatically
generate the class for you (it can't get any easier)!

Then you can make the changes in the automatically generated class so that
it looks something like the following:

internal sealed partial class Settings
{
public Settings()
{
this.SettingsLoaded += this.Settings_SettingsLoaded;
}

private void Settings_SettingsLoaded(object sender,
System.Configuration.SettingsLoadedEventArgs e)
{
if(this.TextEditor == string.Empty)
this.TextEditor =
System.Environment.ExpandEnvironmentVariables(@"%w indir%\NOTEPAD.EXE");
}
}

That's it, if the value of "TextEditor" is empty (this should be your
default value) then you set it to the proper value. After that, the value
should be hardcoded to the exact path.

Does this help you?


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48***********************@roadrunner.com...
>Thanks, but what a pain! I thought this would be such an easy thing to
do, but it doesn't seem to be the case. What would you suggest instead
of the settings class? Is there an easier way to manage user settings for
a small project which is what I'm working on?

"Rene" <a@b.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>>I don't thinkg the ApplicationSettings class is able to evaluate the
expression and return the correct value.

Then only way I see that you can accomplish something like what you want
is to hack the "Settings.Designer" class and hardcode the changes so
that it would look something like this:

[global::System.Configuration.UserScopedSettingAttr ibute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]
public string TextEditor
{
get
{
return System.Environment.GetEnvironmentVariable("windir" ) + "\\"
+ ((string)(this["TextEditor"]));
}
set
{
this["TextEditor"] = value;
}
}

I think thissolution is reeeeeeeeeally cheese. For consistnecy, I guess
you can add code to the "set" accsesor so that get and set are
consistent (the set and get return the same type of string with "windir"
as the prefixed path).

Keep in mind that the designer will overwrite everything every time you
make a change so you will have to constantly remember to update the
file.

I would't recommend going this way but if you have no other choose well
there is an option.....


"Clarks Computing" <Cl*************@nospam.please.comwrote in message
news:48**********************@roadrunner.com.. .
Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say I
create a user setting called TextEditor in the settings designer. I
realize
that I can type a string value such as NOTEPAD.EXE in the Value column.
However, what if I want to make the default value something like the
following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Thanks for any help,




Jun 27 '08 #8
Yep, I get it now. I appreciate your response.
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:eT**************@TK2MSFTNGP03.phx.gbl...
Clarks Computing wrote:
>Hi all,

Question regarding the settings feature in Visual C# 2008. Let's say
I create a user setting called TextEditor in the settings designer. I
realize that I can type a string value such as NOTEPAD.EXE in the
Value column. However, what if I want to make the default value
something like the following:

Environment.GetEnvironmentVariable("windir") + "\\NOTEPAD.EXE"

Is there any way to do this at design time, or what is the best way to
handle this?

Make the default a special string ("__DEFAULT__" or maybe just ""), test
for it and substitute your dynamic value.

Settings can't be dynamic, they are stored in an xml file.
>>
Thanks for any help,


Jun 27 '08 #9

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

Similar topics

3
7083
by: Marti | last post by:
Dear everyone, Its my understanding that IE6 now uses a default text-size of "Small" rather than IE5's "Medium". Since I have used relative font-sizes (usually in ems) on all my sites, I am...
55
4934
by: Haines Brown | last post by:
I've been setting font-size 1em; as the default in my style sheets. Until now, that seemed to be ok. But now I'm beginning to wonder. My aim is to have an easily readable, but not overly large...
0
1711
by: Suzanne | last post by:
Hello experts, I am a VBA newbie. Most of the tricks I apply to my applications I learn from here or google. I couldn't find a solution for the following two things, they both are related to...
2
11487
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
1
6445
by: logicnet.dk | last post by:
Is it possible to decide where user.config is stored by Properties.Settings.Default.Save? The default location seems to be "C:\Documents and Settings\\Local settings\Application Data\\\" and there...
4
3578
by: RedHair | last post by:
I developed a Win form with VS.NET 2005 + .NET 2.0 in C# There are some application settings are "User" scope and stored in xxx.settings, I can access them via Settings class and changethem with...
6
4470
by: AGP | last post by:
VB.NET 2005 I've been working extensively with saving and loading my settings via the My.Settings class. its worked out great except that i cant figure out how to set a default setting that is...
2
11876
Pittaman
by: Pittaman | last post by:
Hello I am creating some crystal reports (for visual studio 2005) based on the content of certain .NET objects. I'm doing this in .NET 2.0. For one of them I'm using a Cross-table to summarize...
7
1603
by: =?Utf-8?B?Tmljb2xhcw==?= | last post by:
Yes another question about databindings. All my controls are have databindings and works fine for navigating, adding, deleting etc. What I want is when I create a New record have those fields...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.