 |
|
 |
the assembly.getassembly() always returns to me projectname.vhost.exe.config
why is this? cant understand why there's a vhost appended to it.
|
|
|
|
 |
|
 |
and it always says cant find project.vhost.exe.config
even though in the constructor i added code to call createconfigfile(), still doesnt work
|
|
|
|
 |
|
 |
This part of the code:
this.ConfigFileName =
Assembly.GetExecutingAssembly().ToString() + ".exe.config";
crashes after I've opened a file in the file dialog, it tries to save the config file in the local directory, e.g.,
fileDialogDirectory\application.exe.config
not c:\program files\application\application.exe.config
|
|
|
|
 |
|
 |
Looks like average level student's XML homework.
|
|
|
|
 |
|
 |
Perhaps you'd like to elaborate oh great one....
|
|
|
|
 |
|
 |
This is some of the worst code I've ever seen - what is the point in being able to specify a configuration file name, when it isn't even used ANYWHERE?!!
|
|
|
|
 |
|
 |
Constructor don´t works if tool using in dll, because Assembly.GetExecutingAssembly() gets the assembly from the dll. The good news is, no one uses bool _bFileExists; drop it.
The solution is:
public ConfigSettings(string sConfigFile)
{
ConstructorHelper(sConfigFile);
}
private void ConstructorHelper(string sConfigFile)
{
if(File.Exists(sConfigFile))
{
this.ConfigFileName = sConfigFile;
}
else
{
throw new Exception("Config File '"+sConfigFile+"' Dosn´t exist");
}
}
And the usage
ConfigSettings conf = new ConfigSettings(Assembly.GetExecutingAssembly().Location + ".config");
I will using the module intensively in the next few days, the Result I will post here.
Greetings: Georg Balog
Georg Balog
eandb@axelero.hu
|
|
|
|
 |
|
 |
Georg,
Thanks for your comments, this class is due to go through an extensive overhaul as there have been many requests for other options.
|
|
|
|
 |
|
 |
I am fustrated with trying your code and after some debugging it really deletes the config file.
What is the error and how can you justify it...
It neither gets the settings or saves them... it only deletes them...
Cheers
|
|
|
|
 |
|
 |
Nick,
This tool is exactly what I'm looking for, great job! I too am having issues with the GetValue() and SetValue() functions returning null values. I tried to make the changes recommended in the GetValue() posting thread below, but that didn't work. I'm trying to add a config file to my C# windows app. My config file code is below. My apps name is ConfigurationExample.exe, and the namespace is ConfigurationExample (I don't know if this will help or not).
?xml version="1.0"?>
configuration>
configSections>
section name="ApplicationData" type="ConfigurationExample.ConfigSettingsSectionHandler, ConfigurationExample" />
/configSections>
ApplicationData>
add key="Height" value="500" />
add key="Width" value="500" />
/ApplicationData>
/configuration>
I took off the < for each of the tags above so it would show in the message.
Is their any way you can post an example app with a working config file?
Thanks
|
|
|
|
 |
|
 |
Manster,
I will have some free time to take a look at it in about two hours, I will try to get an example posted then. Sorry about the delay.
- Nick Parker My Blog | My Articles
|
|
|
|
 |
|
 |
So, had the same problems as everybody else here. The following changes make it work like a charm:
Replace the default constructor with
public ConfigSettings()
{
if(File.Exists(Assembly.GetExecutingAssembly().Location + ".config"))
{
this.ConfigFileName = Assembly.GetExecutingAssembly().Location + ".config";
_bFileExists = true;
}
else
{
_bFileExists = false;
}
}
and replace GetValue() with
public string GetValue(string AttributeName)
{
XmlDocument = new XmlDocument();
try
{
XmlDocument.Load(this.ConfigFileName);
Query = "configuration/" + SectionName;
AppSettingsNode = (XmlElement)this.XmlDocument.SelectSingleNode(this.Query);
if(AppSettingsNode != null)
{
Query += "/add[@key='" + AttributeName.ToString() + "']";
XmlNodeList = this.XmlDocument.SelectNodes(this.Query);
if(XmlNodeList.Count > 0)
Node = (XmlElement)XmlNodeList[0];
return Node.Attributes["value"].Value;
}
}
catch(Exception)
{
}
return String.Empty;
}
This might not be the intended or best way, but it works pretty nice.
Leon[^] - Enterprise Anti-Spam Server
|
|
|
|
 |
|
 |
Is this a feature or a bug of System.Configuration namespace? Maybe your class could be fixed by bypassing this class completely and using an xml reader
|
|
|
|
 |
|
 |
Could you be a little more clear with the problem you are having? Did you change the namespace in the code, not only what is declared but what the method writes out when it creates the file?
- Nick Parker My Blog
|
|
|
|
 |
|
 |
Hope this makes sense and Im doing something completely wrong but here goes;
Your code successfully updates values within the config file however when reading them back it gives the values which were initially loaded when the application started.
This I beleieve is the way in which the .net ConfigurationSettings class works. I think this piece of code is where your use it;
public NameValueCollection GetConfig()
{
return (NameValueCollection)ConfigurationSettings.GetConfig(SectionName);
}
Once I stop the application and restart it then I am able to read in the new value.
This kind of explains it a bit better;
Configuration.ConfigSettings otest = new Configuration.ConfigSettings();
otest.ConfigFileName = "EquilibriumXP.exe.config";
otest.SectionName = "appSettings";
MessageBox.Show(otest.GetValue("SMTPServer"));
otest.SetValue("SMTPServer", "andy");
MessageBox.Show(otest.GetValue("SMTPServer"));
initially SMTPServer had a value of mail-hub. Both messageboxes printed mail-hub. Therefore .net only loads the config once...when the application starts
|
|
|
|
 |
|
 |
Hi there,
Nice code....just what I need
I'm getting a problem though when trying to access a config file using the code below
Configuration.ConfigSettings file = new Configuration.ConfigSettings();
file.SectionName = "TestSettings";
if(!file.FileExists)
{
file.ConfigFileName = "test.config";
file.CreateConfigFile(file.ConfigFileName, file.SectionName);
file.SetValue("test", "russ");
}
string stringValue = file.GetValue("test");
specifically it is the
NameValueCollection col = this.GetConfig();
call in 'GetValue' that is returning a null object
Any ideas why this is?
thanks,
Russ
|
|
|
|
 |
|
 |
Russq wrote:
Any ideas why this is?
Russ, I will look into it tonight, sorry, I am busy until then, however, I would be curious what the .config file looks like following your calls to CreateConfigFile() and SetValue(). I know what they should look like, but I just wondering if something else is happening. I will posting an update soon to reflect some minor changes to the code that should make implementation easier. If you get a chance, post a copy of what the sample config file contains. Thanks.
-Nick Parker
DeveloperNotes.com
|
|
|
|
 |
|
 |
Nick,
Thanks for the quick response...
The file after the call to CreateConfigFile is:
and after the call to SetValue it is:
Hope this help you out,
Russ
|
|
|
|
 |
|
 |
Nick,
Sorry for some reason copy and paste of the xml output didn't work... i'll write it out by hand
After CreateConfigFile
After SetValue
Russ
|
|
|
|
 |
|
 |
Damn....I must be doing something wrong here...i'll try it without the arrows
After CreateConfigFile
?xml version="1.0"?
configuration
configSections
section name="TestSettings" type="Configuration.ConfigSettingsSectionHandler, Configuration"
/configSections
TestSettings
/TestSettings
/configuration
After SetValue
?xml version="1.0"?
configuration
configSections
section name="TestSettings" type="Configuration.ConfigSettingsSectionHandler, Configuration"
/configSections
TestSettings
add key="test" value="russ"
/TestSettings
/configuration
Sorry,
Russ
|
|
|
|
 |
|
 |
i think i'm having the same problem. were you able to get the help you were looking for?
|
|
|
|
 |
|
 |
Mithrang wrote:
i think i'm having the same problem. were you able to get the help you were looking for?
What does your .config file look like? I hope to release an update during my Thanksgiving break next week that will help those that are having problems like this.
-Nick Parker
DeveloperNotes.com
|
|
|
|
 |
|
 |
here's my .config file. thanks for the help
<?xml version="1.0"?> <configuration> <configSections> <section name="ApplicationData" type="Configuration.ConfigSettingsSectionHandler, Configuration" /> </configSections> <ApplicationData> <add key="owl" value="spotted" /> <add key="sloth" value="three-toed" /> </ApplicationData> </configuration>
|
|
|
|
 |
|
 |
Two quick "possible" fixes:
- Remove the <?xml version="1.0"?> in your .config file.
- What is the name of your executing assembly? Is it Configuration?
Again, I hope to post something next week to help with these problems.
-Nick Parker
DeveloperNotes.com
|
|
|
|
 |
|
 |
Nick,
I've just tried your suggestion of removing the xml version element, but unfortunately this didn't work.
With respect to your second point I have tried it by first using the code as an assembly (Configuration) and also by placing the relevant code directly into another assembly/application of a different name and neither worked.
Sorry to be the bearer of bad news. Looking forward to your post next week.
thanks,
Russ
|
|
|
|
 |