joe_pool_is Posted December 30, 2005 Posted December 30, 2005 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? Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted December 30, 2005 Administrators Posted December 30, 2005 http://www.xtremedotnettalk.com/showpost.php?p=452128&postcount=3 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders dynamic_sysop Posted December 30, 2005 Leaders Posted December 30, 2005 (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 December 30, 2005 by dynamic_sysop Quote
joe_pool_is Posted December 31, 2005 Author Posted December 31, 2005 http://www.xtremedotnettalk.com/showpost.php?p=452128&postcount=3Sorry 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! Quote Avoid Sears Home Improvement
Administrators PlausiblyDamp Posted December 31, 2005 Administrators Posted December 31, 2005 If you go through the properties dialog and create your settings there then you can access them, see the attached sample for an example.WindowsApplication1.zip Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joe_pool_is Posted December 31, 2005 Author Posted December 31, 2005 If you go through the properties dialog and create your settings there then you can access them' date=' see the attached sample for an example.[/quote']That makes sense. Sorry for being so thick headed about this. Thanks for your patience. Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.