473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to check if appSetting exists in web config file

Hi

I have a class library which takes some values from web config / app
config files when called.
I am initialising these values when my object gets called.

Is there any method to find out if app Settings tag is defined in the
file?

here is my code for initislisation

public class WriteFile
{
// Initialising variables from the config Files
private static readonly string FullFilePath =
GetFilePathConfigSetting("FilePath");

and here is the code for GetFilePathConfigSetting which checks for the
value

public static string GetFilePathConfigSetting(string name)
{

string retVal = ConfigurationSettings.AppSettings[name];

if (retVal == null)
{

return "defaultfile.txt";
}

return retVal;

}

The problem is that when I deliberately remove appSettings tag or the
Filepath tag from the web config.. there is an exception.

can anybody tell where I am making a mistake?

Thanks in advance
Akash

Jul 27 '06 #1
1 9988
Here is the problem..

if (ConfigurationSettings.AppSettings[name] != null)
{
// Now do your magic..
}

"softwareakash" <so***********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Hi

I have a class library which takes some values from web config / app
config files when called.
I am initialising these values when my object gets called.

Is there any method to find out if app Settings tag is defined in the
file?

here is my code for initislisation

public class WriteFile
{
// Initialising variables from the config Files
private static readonly string FullFilePath =
GetFilePathConfigSetting("FilePath");

and here is the code for GetFilePathConfigSetting which checks for the
value

public static string GetFilePathConfigSetting(string name)
{

string retVal = ConfigurationSettings.AppSettings[name];

if (retVal == null)
{

return "defaultfile.txt";
}

return retVal;

}

The problem is that when I deliberately remove appSettings tag or the
Filepath tag from the web config.. there is an exception.

can anybody tell where I am making a mistake?

Thanks in advance
Akash

Jul 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ellis Yu | last post by:
Dear All, I use function configurationsettings.appsetting to retrieve the connection string value which stored in a file app.config. At the beginning, it's fine that it can pick up the value...
2
by: keith | last post by:
In my app, an executable (app.exe) calls functions from an assembly dll (subapp.dll). app.exe has config file: app.exe.config <?xml version="1.0" encoding="utf-8" ?> <configuration>...
1
by: Maziar Aflatoun | last post by:
Hi everyone, I'm tring to read the appSettings from my Web.config file in Visual Studio.Net (Code behind page) and it doesn't recognize ConfigurationSettings.AppSetting? Yet it works in my .aspx...
2
by: John Spiegel | last post by:
Hi all, I'm looking for suggestions on storing classifications of application settings in a WinForms app. I've got a couple ideas using XML config files. One is to have a set of .config files...
10
by: Ricardo Luceac | last post by:
Hi all. I'm having a problem with this, I have look if a file exists, if don't wait till it is created and if it exists I need to open it. I do the following: for (; ; ) {
6
by: Mats-Lennart Hansson | last post by:
Hi, In a windows service, I have some appSettings. If I during runtime changes one of the values, is it availabele to the service from that moment? Or do I have to restart the service before I can...
4
by: softwareakash | last post by:
Hi I have a dll which logs some values in a text file. In this I am initialising some values as soon as the object gets called like this public class Logger { // Initialising variables from...
16
by: Robert Dufour | last post by:
Here's the class code snippet Imports System.Configuration.ConfigurationManager Public Class Class1 Public _strTestSetting As String Public Sub SetTestsetting()
1
by: timexsinclair2068 | last post by:
This is a very simple question. Is there a simple,short way of checking if the application's App.Config file exists? Thanks!
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.