jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Editing a web.config to change an apSetting value

Hi all,
I've got a web.config file, with the AppSettings stored in it. These are stored as follows:

Code: Select all

<configuration>
	<appSettings>
		<add key="dataDSN" value="provider=ASAProv.90;data source=LLB_V9Server123;uid=ASPNET;pwd=aspnet_llb" />
		<add key="logDSN" value="provider=ASAProv.90;data source=systemsupportDev;uid=ASPNET;pwd=aspnet_ss" />
	</appSettings>
<!-- lots of other sections etc. -->
</configuration>
On installation, I need to be able to edit the datDSN value with a value stored in an Installer property.

The XML editor only gives options to update the 'first matching', 'all matching' or 'add as new sibling'. The problem with the above config file structure is that the two appSettings appear in the editor with the same element names - i.e. 'add', with no mechanism for further differentiating between the dataDSN and logDSN values.

Is there a way of achieving this with the XML editor, or do I have to use a different mechanism?

Thanks,

James
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Editing a web.config to change an apSetting value

Hi James,

Yes, this can be done with the XML editor. You can try following these steps:
- import the configuration file as an XML in your project
- for the element with the "dataDSN" key use the "Update" and "First matching" options
- edit the key attribute and set the "Is identifier attribute" option for it in the Edit Attribute dialog
- do the same for the other elements with a key attribute
- for the element you want to modify according to the user options you can use a custom property for the value attribute

During install the elements will be searched based on their identifiers. This way, you can use the property only for the element which has the key "dataDSN".

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
jlavery
Posts: 27
Joined: Tue Oct 14, 2008 4:56 pm

Re: Editing a web.config to change an apSetting value

Hi Cosmin,
Fantastic - exactly what I was looking for.

Thanks, as always, for great support.

Regards,

James

Return to “Common Problems”