Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now