|
-
January 16th, 2010, 02:43 AM
#1
Regarding .config files
Hï!
If the "AddrColWidths" entry is missing in the config file my last code line throws an exception. Is there a common way to check if the entry exists before trying to read it?
I also wonder if there is an easy way to check wether the .config file exists, for example through the config object. I cant find such a way.
Code:
String ^exePath = Reflection::Assembly::GetExecutingAssembly()->Location;
System::Configuration::Configuration ^config =
ConfigurationManager::OpenExeConfiguration(exePath);
AppSettingsSection ^appSettingsSection =
(AppSettingsSection^)config->GetSection("appSettings");
CommaDelimitedStringCollectionConverter^ converter =
gcnew CommaDelimitedStringCollectionConverter();
CommaDelimitedStringCollection^ collection =
(CommaDelimitedStringCollection^)converter->ConvertFrom(appSettingsSection->Settings["AddrColWidths"]->Value);
Best regards
Mattias
.NET 3.5, VS 2008 Express, SQL Server 2008 Express
-
January 16th, 2010, 07:43 AM
#2
Re: Regarding .config files
from my experience I'd discourage you from using .config files. I have always had problems with lost settings in a new app version etc. now I use the windows registry and all problems are gone. (I was to lazy to write my own config wrapper so using the registry was easier but the default .net .config files are evil)
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 16th, 2010, 10:51 AM
#3
Re: Regarding .config files
Well, maybe you´re right, but still, is there an answer to my questions?
.NET 3.5, VS 2008 Express, SQL Server 2008 Express
-
January 16th, 2010, 12:26 PM
#4
Re: Regarding .config files
I think the best way is to catch the ConfigurationErrorsException like in msdn examples. some config wrapper could be very useful.
Last edited by memeloo; January 16th, 2010 at 12:29 PM.
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 18th, 2010, 06:34 PM
#5
Re: Regarding .config files
You can check for nulls :
Code:
System::Configuration::Configuration ^config =
ConfigurationManager::OpenExeConfiguration(exePath);
if (config != nullptr)
{
AppSettingsSection ^appSettingsSection =
(AppSettingsSection^)config->GetSection("appSettings");
if (appSettingsSection != nullptr)
{
if (appSettingsSection->Settings["AddrColWidths"] != nullptr)
{
CommaDelimitedStringCollectionConverter^ converter =
gcnew CommaDelimitedStringCollectionConverter();
CommaDelimitedStringCollection^ collection =
(CommaDelimitedStringCollection^)converter->ConvertFrom(appSettingsSection->Settings["AddrColWidths"]->Value);
}
}
}
Darwen.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|