Solved

Webconfig + webservice + vb.net

Posted on 2007-11-14
2
436 Views
Last Modified: 2008-02-01
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
Comment
Question by:YRKS
2 Comments
 
LVL 21

Accepted Solution

by:
surajguptha earned 250 total points
ID: 20285615
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
 
LVL 15

Assisted Solution

by:Solar_Flare
Solar_Flare earned 250 total points
ID: 20285636
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question