• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

Webconfig + webservice + vb.net

I have a basic question. I am in the process of cleaning up some code. I have a directory path stored in my webconfig file of a web service.
<add key="FilePath" value="c:\\projects\data\spider\" />

Dim FilePath as string
 FilePath=   System.Configuration.ConfigurationManager.AppSettings("FilePath")
It works fine .

In my web service I have a few methods which use this file path. In stead of calling this
Dim FilePath as string
 FilePath=   System.Configuration.ConfigurationManager.AppSettings("FilePath")
 in each and every method can I not set this up as when I start my service instead of always reading it from the webconfig file.
Where would I place this code of line such that all methods can access it? Is it even doable in a webservice.
Just curious!!
0
YRKS
Asked:
YRKS
2 Solutions
 
surajgupthaCommented:
The reason we have the AppSettings is because we dont have to put the app setting value in 10 different places. Instead we put it in the config file and call it with some name. That by itself is a simplification.

If you want it to be made even simpler.
You can write a class that would read the configuration file. In the get property you can add this code

But again if it was me i would just leave it as Configmanager :)
0
 
Solar_FlareCommented:
YRKS,

the web.config file is loaded into memory when the application starts, so in fact it will not be hitting the disk every time you ask for the filepath.

if you really wanted to, you could put it in a static/shared object and use that object everywhere in your code but since it's not hitting the disk that probably isn't necessary.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now