Setup user scope settings on Install

A

active T

Hello,

Is it possible to setup the user scope settings during the install of
a application.

In VS2005 I create a setup project.
I add a installer class into my application project and override the
installer.

public override void Install(System.Collections.IDictionary
stateSaver)
{
base.Install(stateSaver);
String url = Context.Parameters["WebURL"];
Settings UserSettings = new Settings();
Consol.WriteLine("The new url = " + url);
UserSettings .WebURL = url;
UserSettings .Save();
}


but when i'm running my application the settings are not set, but the
application is comming into my install function with the right
parameter.
 
S

SJMac

Here's an approach that I've been shown, which can be easilly tweaked to add
new values for application settings (like connection strings) which are not
writable using the Settings API:

In your installer class, instead of using the settings API you can open the
config file in to an XML DOM document, manipulate it using the DOM API, and
then save the XML DOM document.

For example:

public override void Install(System.Collections.IDictionary
stateSaver)
{
base.Install(stateSaver);
private XmlDocument doc;

string configpath = this.Context.Parameters["assemblypath"] +
".config";
string paramXpath =
String.Format("configuration/userSettings/YOUR_APP_NAME.Properties.Settings/setting[@name=\"{0}\"]", "YOUR_PARAM_NAME");

doc = new XmlDocument();
using (XmlTextReader reader = new XmlTextReader(configpath))
{
doc.Load(reader);
}

XmlNode node = doc.SelectSingleNode(paramXpath);
// Write param value
if (node != null &&
this.Context.Parameters.ContainsKey("YOUR_PARAM_NAME") &&

!String.IsNullOrEmpty(this.Context.Parameters["YOUR_PARAM_NAME"]))
{
node.InnerText = this.Context.Parameters["YOUR_PARAM_NAME"];
}

// Save changes
doc.Save(configpath);
}

I suspect that could be cleaned up - I hope it's helpful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top