Solved

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

Posted on 2011-03-05
4
994 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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