?
Solved

How to declare\read value from app.config file - VB Express 2010

Posted on 2011-03-05
4
Medium Priority
?
1,034 Views
Last Modified: 2012-05-11
I need to be able to set the web service URL by editing the .exe.config file when I deploy this to end users.

This setting is a Web Service URL type in My Project>>Settings.

I tried to read the value this way but get an error:

Public ws_test As New localhost.IDataCollectionservice()

ws_test.Url = System.Configuration.ConfigurationManager.AppSettings("JobBOSS_AutoCrib_Integration_localhost_IDataCollectionservice")

"An error occurred creating the form. See Exception.InnerException for details.  The error is: Value cannot be null.
Parameter name: uriString"

I've checked My Project>>Settings and this is the value for this object.  If I can't get it to read my local web service path, I know it's not going to work when I try to edit the .exe.config file on an end user's machine.

Your thoughts on how to resolve this would be appreciated.
0
Comment
Question by:JMO9966
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
LIONKING earned 2000 total points
ID: 35043666
If you're reading from an app.config, you can add an <appSettings> section in the configuration section of your app.config.
Something like :
<configuration>
      <appSettings>
            <add key="MyKey" value="MyValue"/>
       </appSettings>
</configuration>

In your code you would acces it by using something like:
ConfigurationManager.AppSettings("MyKey")

You'd only have to import the system.configuration namespace.
0
 

Author Comment

by:JMO9966
ID: 35043842
Okay, I need to back up a bit.  I Know how to add setting to My Project>>Settings and I have two settings here, one is  a String type and the second is a Web Service URL type.

I can read these via my code with the following code:

        ws_test.Url = My.Settings.Integration_localhost_IDataCollectionservice
        strTest = My.Settings.Path

In order to deploy this, I was thinking I needed to get my code to read from the .exe.config (app.config in my development environment) file which I will edit on each user's machine to get the path and web service correct.      

I was attempting to use this code, but I get the error I mentioned earlier for the web service url variable and the strTest variable is = "" after this line runs so neither one is ready from app.config??

strTest = System.Configuration.ConfigurationManager.AppSettings("Path")
ws_test.Url = System.Configuration.ConfigurationManager.AppSettings("JobBOSS_AutoCrib_Integration_localhost_IDataCollectionservice")




0
 
LVL 13

Expert Comment

by:LIONKING
ID: 35043907
First of all, sorry if my reply sounded harsh... I didn't mean it that way...

If you're using a regular string for the URL, you could change the type to String and not Web Service URL. Maybe that way you can catch the value as you're doing with the String type setting you already have.
0
 

Author Closing Comment

by:JMO9966
ID: 35411501
Thanks
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

601 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