Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-05
4
Medium Priority
?
1,008 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 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

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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