Solved

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

Posted on 2011-03-05
4
985 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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