473,770 Members | 4,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using App.cofig

I am using App.config to read strings. But when ever I try to read
strings in my C# application it always returns null.
My App.config
*************** *************** *************** ***************
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSetings>
<add key="default_di r" value="c:\\defa ult\file.txt"/>
</appSetings>
</configuration>
*************** *************** *************** ***************
My C# sample for reading keys.
using System.Configur ation;

NameValueCollec tion settings;
string default_dir;
settings = ConfigurationSe ttings.AppSetti ngs;
default_dir = settings["default_di r"];
*************** *************** *************** *************** *
It is returning default_dir is equal "null" but it should
"c:\\default\fi le.txt" .

Nov 17 '05 #1
6 3177
appSettings not appSetings ;)

"inpreet" <in*****@gmail. com> schrieb im Newsbeitrag
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I am using App.config to read strings. But when ever I try to read
strings in my C# application it always returns null.
My App.config
*************** *************** *************** ***************
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSetings>
<add key="default_di r" value="c:\\defa ult\file.txt"/>
</appSetings>
</configuration>
*************** *************** *************** ***************
My C# sample for reading keys.
using System.Configur ation;

NameValueCollec tion settings;
string default_dir;
settings = ConfigurationSe ttings.AppSetti ngs;
default_dir = settings["default_di r"];
*************** *************** *************** *************** *
It is returning default_dir is equal "null" but it should
"c:\\default\fi le.txt" .

Nov 17 '05 #2
"inpreet" <in*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I am using App.config to read strings. But when ever I try to read
strings in my C# application it always returns null.
My App.config
*************** *************** *************** ***************
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSetings>
<add key="default_di r" value="c:\\defa ult\file.txt"/>
</appSetings>
</configuration>
*************** *************** *************** ***************
My C# sample for reading keys.
using System.Configur ation;

NameValueCollec tion settings;
string default_dir;
settings = ConfigurationSe ttings.AppSetti ngs;
default_dir = settings["default_di r"];
*************** *************** *************** *************** *
It is returning default_dir is equal "null" but it should
"c:\\default\fi le.txt" .


Just to be clear. app.config is a Visual Studio thing. VS copies this file
to the build target directory (e.g. bin\debug) as <appname>.exe.c onfig. This
file is the one that .NET automatically picks up. So if you have an
application called foo.exe the config file is called foo.exe.config

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #3
I have readfile.exe and I tried my config file name as
readfile.exe.co nfig and readfile.config with build action as none as
well as content. but nothing is working. Still I am getting null value.

*************** ****readfile.ex e.config ****
readfile.config *************** **********
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="default_di r" value="c:\\defa ult\file.txt"/>
</appSettings>
</configuration>
*************** *************** *************** *************** *************** *************

Nov 17 '05 #4
> <appSetings>

That should read <appSettings> with two "t" in the mdidle there. Maybe
that typo is causing your problem?

Marc
Nov 17 '05 #5
>I have readfile.exe and I tried my config file name as
readfile.exe.c onfig and readfile.config with build action as none as
well as content. but nothing is working. Still I am getting null value.


You have to call the file "app.config " (literally that - DO NOT
substitute "app" for your app's name!!) - and then VS.NET will
automagically rename it to "readfile.exe.c onfig" and copy it to your
output directory. That's the way to go.

Marc

Nov 17 '05 #6
Have you tried

default_dir = (string) ConfigurationSe ttings.AppSetti ngs["default_di r"];

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"inpreet" <in*****@gmail. com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I have readfile.exe and I tried my config file name as
readfile.exe.co nfig and readfile.config with build action as none as
well as content. but nothing is working. Still I am getting null value.

*************** ****readfile.ex e.config ****
readfile.config *************** **********
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="default_di r" value="c:\\defa ult\file.txt"/>
</appSettings>
</configuration>
*************** *************** *************** *************** *************** *************

Nov 17 '05 #7

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

Similar topics

7
2309
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site. The only reason I know that is happening is because I keep track of the pages executed by the user to see how they have traversed the site. Has anyone every seen anything like this before? Regards, Aaron Prohaska
0
2025
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent users So I designed the project as master Node that has all administration
0
285
by: crawlerxp | last post by:
This is the problem: I do not get the output I need when encoding and decoding data using rijndael alghoritm. Look at the code and see what the problem is actually: Please paste this code into your Visual Studio and compile it + run it; so you can see what the actual problem is. Thanks. code:
4
2404
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
2
9289
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which reads "Invalid use of null". The remainder of the options in the Command Button Wizard are then unavailable and the button wil not work. The only solution is to log on to a different workstation. Any ideas?
9
2823
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am facing. Please please help me to solve this as soon as possible. So here we go ... I am not able to take the screen shot of the windows form based "Smart
5
2735
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
9764
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
16
4929
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.