Last post Aug 11, 2008 08:09 PM by JustWantAnAnswer
Aug 04, 2008 07:09 PM|JustWantAnAnswer|LINK
Surely it's not the case that I have to create a reader and read the lines as an XML file and hunt for what I want. With VS2005, using the automated tools, it's putting my settings someplace other than appSettings, but I can't seem to find anything in C#
that will read the settings. I keep finding things that are types and tell me that if found my setting, but since it's a type, it won't read the string that it is defined as.
This is what shows up in the config file:
MSDN says to do this:
pathToIntranetArc = rootWebConfig1.AppSettings.Settings[
but when i run it, it says rootWebConfig1.AppSettings.Settings["PathToIntranetArc"] is null
Isn't there a settings object created when the page is loaded?
C# 2005 Generics
Aug 04, 2008 07:26 PM|budugu|LINK
I guess , you have to add it to appSettings, Something like this..
<add key="it" value=" "/> </appSettings>
Aug 04, 2008 07:51 PM|JustWantAnAnswer|LINK
I tried that, but it didn't work. I certainly did back in VS 2003, but we have to move on, I suppose.
However, in a sample project for something else, I found a config file with this new type of applicationSettings rather than the simple appSettings, and I found the way he was reading them to be quite simple, though I doubt I would have ever guessed it.
pathToScripts = MoHuntEdWebApp.Properties.
So, instead of using the string "PathToCmdFiles" as the index into a collection, in C# this is apparently now a member of the default class. I guess that's what "Default" means in this context. I saw the choice in intellisense, if just
didn't occur to me that default would be useful for finding out my current settings. The word seemed to imply generic stuff of some kind. But if you put it in, then intellisense will display all your settings names.
Aug 04, 2008 10:50 PM|SGWellens|LINK
Here is some sample code:
// Reading a key
String Version = ConfigurationManager.AppSettings["VersionOfWebSite"];
// Writing a key
ExeConfigurationFileMap FileMap = new ExeConfigurationFileMap();
FileMap.ExeConfigFilename = Server.MapPath(@"~\Web.config");
Configuration Config = ConfigurationManager.OpenMappedExeConfiguration(FileMap, ConfigurationUserLevel.None);
Aug 05, 2008 02:40 PM|JustWantAnAnswer|LINK
This only works if in fact the system has put your settings in <appSettings />. However, in VS2005, if you use the IDE (i.e. the application or website properties) to create and manage your key-value pairs, it puts them in a different place. This returns
a null in my situation. And while I could change it around, now the problem will be that the network group will have to edit the config files manually instead of being able to use the IIS properties for the website.
Aug 11, 2008 05:20 PM|JustWantAnAnswer|LINK
VS2005 no longer creates "appSettings" entries, instead there is now a two stage entry, one part that defines what sections are present in the file, and the other part those sections. Where can I find out how to read information from these new sections that
will work for both web applications and web services?
I had marked myself as answered by using
pathToScripts = MoHuntEdWebApp.Properties.Settings.Default.PathToCmdFiles;
But I had to move the config information to a web service, and this doesn't work any more. (Yes, I changed the first name to the name of the webservice).
It says my MoHuntEdWebSvc does not have ".Properties". However I set up the web config by using the properities item in the solution explorer. The result is entries in the web.config file that are the same for the app as the web service:
Here is the type of stuff found in both config files
Up at the top there is this business, which is surely what the IDE and IIS use when presenting a graphic wrapper around editing the application Properties. I can see where the "ApplicationName.Properties.Settings.Default.NameOfKey"
can be used to find stuff. But when I try to write this in C# it keeps telling me that the only right way to do it is what was suggested earlier, "ConfigurationManager.AppSettings["VersionOfWebSite"];"
But that only works with the old style web.config structure that has an
appSettings section in the webconfig.
Aug 11, 2008 08:09 PM|JustWantAnAnswer|LINK
How am I supposed to know I need to prepend "global::"?
I found it by clicking on find definition over in the other app where the Properties of the app exist. That sent me to a generated file, reference.cs, where I saw this "global::" thing.