1) Add an "Application Configurate File" to your project. It will be named
"app.config" during development. After a build, it will automatically be
copied to the runtime folder with the name "yourappname.exe.config".
2) use an appSettings section as detailed in my first response above, and
access the items with ConfigurationManager.AppSettting["keyname"];
That's it, aside from remembering to convert string values to integers.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"(E-Mail Removed)" wrote:
> Peter,
> I seem to be having some difficulties with this, what is the simplest
> way to use a config file with a windows service? All i need it to do
> is be able to contain an int or a string.
>
>
>
> Peter wrote:
> > Cody,
> > ConfigurationManager.AppSettings is only for reading the standard
> > appSettings standalone section that looks like this:
> >
> > <appSettings>
> > <add key="yourKey" value="yourValue" />
> > </appSettings>
> >
> > You need to use one of the configurationSettings reader classes to read your
> > custom "applicationSettings" Section.
> > Peter
> >
> > --
> > Co-founder, Eggheadcafe.com developer portal:
> > http://www.eggheadcafe.com
> > UnBlog:
> > http://petesbloggerama.blogspot.com
> >
> >
> >
> >
> > "(E-Mail Removed)" wrote:
> >
> > > I keep getting a null reference when trying to access my config file
> > > through my windows service, I have placed the xml config file in my
> > > debug folder with my .exe, and my code is shown below.
> > >
> > > //where I call the app.config file
> > > f =
> > > X10Unified.Senders.Firecracker.GetInstance(Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["COM_Port"]));
> > >
> > > //the config file
> > > <?xml version="1.0" encoding="utf-8" ?>
> > > <configuration>
> > > <configSections>
> > > <sectionGroup name="applicationSettings"
> > > type="System.Configuration.ApplicationSettingsGroup, System,
> > > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
> > > <section name="namespace.Properties.Settings"
> > > type="System.Configuration.ClientSettingsSection, System,
> > > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
> > > requirePermission="false" />
> > > </sectionGroup>
> > > </configSections>
> > > <applicationSettings>
> > > <namespace.Properties.Settings>
> > > <setting name="namespace_Service_gLink"
> > > serializeAs="String">
> > > <value>url</value>
> > > </setting>
> > > <setting name="COM_Port" serializeAs="String">
> > > <value>"3"</value>
> > > </setting>
> > > </namespace.Properties.Settings>
> > > </applicationSettings>
> > > </configuration>
> > >
> > >
>
>