Solved

Webconfig + webservice + vb.net

Posted on 2007-11-14
2
408 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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now