473,320 Members | 1,746 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.

retrieving a value from app.config

My appconfig has this line in it:
<appSettings>
<!--
The Location of the reports.
-->
<add key="ReportsLocation" value="C:\Reports\" />

However I am not able to retrieve this line value
my code to retrieve it is:
string
repname=System.Configuration.ConfigurationSettings .AppSettings.GetValues("ReportsLocation").ToString ();
reports1.ReportName = repname + "SQL_VehSchedule.rpt";

the value returned is "System.String[]SQL_VehSchedule.rpt" not
"c:\Reports\VehicleSchedule.rpt"

What am I typing wrong ?

Regards,

Vincent
Nov 16 '05 #1
2 10446
Vincent Haakmat wrote:
My appconfig has this line in it:
<appSettings>
<!--
The Location of the reports.
-->
<add key="ReportsLocation" value="C:\Reports\" />

However I am not able to retrieve this line value
my code to retrieve it is:
string
repname=System.Configuration.ConfigurationSettings .AppSettings.GetValues("Re
portsLocation").ToString(); reports1.ReportName = repname + "SQL_VehSchedule.rpt";

the value returned is "System.String[]SQL_VehSchedule.rpt" not
"c:\Reports\VehicleSchedule.rpt"

What am I typing wrong ?


Use
System.Configuration.ConfigurationSettings.AppSett ings["ReportsLocation"]
instead of GetValues().
--
Tom Porterfield
Nov 16 '05 #2
Vincent,

Don't use the GetValues method. Rather, use the indexer, like this:

repname= (string)
System.Configuration.ConfigurationSettings.AppSett ings["ReportsLocation"];

Also, you don't need to call ToString, as it will be a string when
returned to you. You just need to cast.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vincent Haakmat" <vh******@nagico.com> wrote in message
news:eQ**************@TK2MSFTNGP10.phx.gbl...
My appconfig has this line in it:
<appSettings>
<!--
The Location of the reports.
-->
<add key="ReportsLocation" value="C:\Reports\" />

However I am not able to retrieve this line value
my code to retrieve it is:
string
repname=System.Configuration.ConfigurationSettings .AppSettings.GetValues("ReportsLocation").ToString ();
reports1.ReportName = repname + "SQL_VehSchedule.rpt";

the value returned is "System.String[]SQL_VehSchedule.rpt" not
"c:\Reports\VehicleSchedule.rpt"

What am I typing wrong ?

Regards,

Vincent

Nov 16 '05 #3

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

Similar topics

8
by: Steve | last post by:
Can anyone tell me the preferred method for writing and retrieving persistent information using .Net. Specifically, I am referring to information that you used to see in registry keys or .ini...
3
by: Charlie | last post by:
Hi: I created a config file to retrieve DSN at runtime from a C# library project (DLL). I name the file same as DLL (libRADIUS.config). Here is the contents of the file... <?xml...
1
by: Dave | last post by:
Hello. I want to create some custom settings in my Web.config file and then retrieve it in my application, exactly I want to store some connection string for my database. I'm adding these...
1
by: DS | last post by:
Hi all, Will appreciate if someone can help me with this problem. I am using VS 2003 on Win2000, sp 4. 2GB RAM. Session data is stored on DB on another machine in network. Can connect to the...
10
by: Dan | last post by:
I use the settings grid to create a setting named "ServerName". Now i want to retrieve it in code and i can't figure out how. This should be incredibly obvious but i cant get it. I have tried...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
1
by: durai1117 | last post by:
i want one help from u friends my requirement is to store 2 values in app.config file i dnt know how to store in it. and next thing is i have to get that values and with that values i...
3
by: Jordan S. | last post by:
How would it be possible for an ASP.NET Web application, in it's Application_Start event procedure, to programmatically determine the Web site (in IIS) that the Web app is running under/for. Say...
4
balabaster
by: balabaster | last post by:
Okay, I need some inspiration to get me started on the implementation of an idea I've got. I want to specify in the config file of my .NET app that will give me a reference to a property on one of...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.