app-config

Setting the service URL at runtime

老子叫甜甜 提交于 2019-11-27 04:48:14
问题 When I am adding the "Web Reference" we are giving the address to the asmx page to visual studio. How Can I set this at run time? 回答1: Just set the Url property of the object before you call any of the service methods: YourService service = new YourService(); service.Url = "http://some.other.url/"; // Now you're ready to call your service method service.SomeUsefulMethod(); 回答2: I would have upvoted one of the other answers - they're almost correct. using (YourService service = new YourService

How can I read/write app.config settings at runtime without using user settings?

大憨熊 提交于 2019-11-27 03:40:45
I'm looking for a way to store application or machine level settings that can be written to at runtime using Application Settings . User settings allow read/write but application settings do not. I have been using user settings for saving settings like this at runtime but this has really proven to be impractical for the following reasons: All users of the machine need to share settings. In support calls (especially in crisis situations) it is difficult to explain to users/employees where to find and modify these settings manually (appdata is a hidden folder among other things). New versions of

WCF Configuration - Split it out of app.config

时光毁灭记忆、已成空白 提交于 2019-11-27 03:13:38
问题 I have a specific requirement to remove all client WCF configuration (<system.serviceModel>) out of the main app.config file, and into a separate XML file. The behaviour I would like to see is similar to that available in the appSettings section using the File="" directive. In fact, I'd ideally like to be able to specify a separate file for each consumed service... I know I can build a custom ChannelBuilder factory that reads config data from an XML file (or a series of them), but I would

Nested Configuration Section app.config

余生长醉 提交于 2019-11-27 03:10:58
问题 I don't find any examples of how to access such a nested configuration section in a app.config <my.configuration> <emailNotification> <to value="me@you.com" /> <from value="he@you.com" /> <subject value="Subject" /> <smtpHost value="smtp.you.com" /> <triggers> <add name="1" varAlias="Var1" lower="-200" upper="-150"/> </triggers> </emailNotification> </my.configuration> I used ConfigurationElementCollection and ConfigurationElement before. But I don't know how to do the above? 回答1: You need to

Centralize connection strings for multiple projects within the same solution

◇◆丶佛笑我妖孽 提交于 2019-11-27 01:59:33
问题 I currently have three projects in my solution that all have their own App.config file with the same exact connection string. Is there a way to consolidate the connections strings / app.config files so that I only need to make changes to one location? 回答1: There's a few ways you could do it: Put common configuration settings in machine.config as shown here Put common configuration settings in a central file and link to that in each projects's app.config as shown here Store the configuration

Store String Array In appSettings?

折月煮酒 提交于 2019-11-27 01:42:43
I'd like to store a one dimensional string array as an entry in my appSettings . I can't simply separate elements with , or | because the elements themselves could contain those characters. I was thinking of storing the array as JSON then deserializing it using the JavaScriptSerializer . Is there a "right" / better way to do this? (My JSON idea feels kinda hacky) You could use the AppSettings with a System.Collections.Specialized.StringCollection . var myStringCollection = Properties.Settings.Default.MyCollection; foreach (String value in myCollection) { // do something } Each value is

Fix: The Global element 'configuration' has already been declared

妖精的绣舞 提交于 2019-11-27 00:19:35
问题 I used the second solution of How to resolve "Could not find schema information for the element/attribute <xxx>"? I.e. created a XSD with the button to create a scheme. I changed the stylesheet in app.config to app.xsd but now I get the warning: The Global element 'configuration' has already been declared in app.xsd Even when changing the name the warning is shown. Does anybody have a solution for this? 回答1: I had a similar problem to the question you are referring to, I followed these

How to get a List<string> collection of values from app.config in WPF?

蓝咒 提交于 2019-11-27 00:16:40
The following example fills the ItemsControl with a List of BackupDirectories which I get from code. How can I change this so that I get the same information from the app.config file? XAML: <Window x:Class="TestReadMultipler2343.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"/> <ColumnDefinition

Custom app.config Config Section Handler

纵饮孤独 提交于 2019-11-27 00:06:18
What is the correct way to pick up the list of "pages" via a class that inherits from System.Configuration.Section if I used a app.config like this? <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="XrbSettings" type="Xrb.UI.XrbSettings,Xrb.UI" /> </configSections> <XrbSettings> <pages> <add title="Google" url="http://www.google.com" /> <add title="Yahoo" url="http://www.yahoo.com" /> </pages> </XrbSettings> </configuration> Luke Quinane First you add a property in the class that extends Section: [ConfigurationProperty("pages", IsDefaultCollection = false)

How do you use sections in c# 4.0 app.config?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 00:00:48
问题 I want to use my app config to store the settings for 2 companys, and i'd prefer if it was possible to use a section to seperate the data for one from the other rather then giving them diffrent key names. I have been checking online but i seem to get a bit overwhelmed when people use sections or find outdated easy ways to use them. could anyone pass me a beginner guide on them? Below is an example of what my app.config would look like: <configSections> <section name="FBI" type="" /> <section