Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Microsoft has a new Settings field in Visual Studio 2005 which can be accessed at design time via "Project | <Project Name> Properties..." item on the menu bar.

 

I have successfully created the Settings fields for my project, but I need to read/write values for the user.config file using these settings at run time. I found an article on how to do it here: http://msdn2.microsoft.com/en-us/library/shytyc55.aspx but it seems to only be accessible via the "My" keyword, which is not part of the C# language.

 

Does anyone know the proper way to access this information using C# on 2005?

  • Leaders
Posted (edited)

as another alternative method, you can access the settings part ( as with My.Settings ) like this ...

 
[size=2][color=#0000ff]private [/color][/size][size=2][color=#0000ff]void[/color][/size][size=2] button1_Click([/size][size=2][color=#0000ff]object[/color][/size][size=2] sender, [/size][size=2][color=#008080]EventArgs[/color][/size][size=2] e)[/size]
[size=2]{
WindowsApplication1.Properties.[/size][size=2][color=#008080]Settings[/color][/size][size=2] s = [/size][size=2][color=#0000ff]new[/color][/size][size=2] WindowsApplication1.Properties.[/size][size=2][color=#008080]Settings[/color][/size][size=2]();

[/size][size=2][color=#0000ff]foreach[/color][/size][size=2] (System.Configuration.[/size][size=2][color=#008080]SettingsProperty[/color][/size][size=2] prop [/size][size=2][color=#0000ff]in[/color][/size][size=2] s.Properties)[/size]
[size=2]	{
[/size][size=2][color=#008080]	Console[/color][/size][size=2].WriteLine(prop.DefaultValue.ToString());
}
}[/size]

just for fun as another method :) , happy new year :D

Edited by dynamic_sysop

Posted
Sorry PlausiblyDamp, but I just was not able to make that work. Maybe it did not explain enough to me. I already had those settings defined in the project's Properties segment, but I did not know how to access them via the program (i.e. read/write the data with C#).

 

as another alternative method' date=' you can access the settings part ( as with My.Settings ) like this ...[/quote']dynamic_sysop: I did get this to work. Thanks! I noticed that all of my Settings were stored under the "Default" tag. Does this mean that others can be created on the fly as well? I'm going to play around with that, but if you know any more secrets, I would appreciate them!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...