Hi Folks,

I've just upgraded an old VB6 app to VB2008 - all has gone well and I'm pleased with the new .net features.

However I need to holds the common settings for all of the apps ona server (UNC path). Previously I used an ini file on the server and the application was told to look there via a command switch.

I understand that I'm trying to use .net in an old fashioned way by not packaging it for web update & delivery but that's a contraint of the architecture I need to work with.

Is there any way to force my application to use the application.exe.config file from a set location rather than the user data area that .net automatically writes it to? Even if not on a server path, then in the application directory where we can push update it?

Otherwise I'll need to rewrite it all again using ini files and losing the ease of the built in application settings...

Many thanks for any help.

Adam.

Previously I used an ini file on the server and the application was told to look there via a command switch.

The old way was to store the information in .ini files or in the system registry. In VB.NET, every application can have a configuration file, which is really just an XML file.

To add a config file to your application, open up the Solution Explorer and click on Add -> Add New Item and select Application Configuration File.

You can add values to the XML file:

<?xml version="1.0" encoding=    "utf-8" ?>
<configuration>
<appSettings>
    <add key="DatabasePath" value="c:\\projects\data\spider.mdb" />
    <add key="SupportEmail" value="webmaster-1@dotnetspider.com"/>
</appSettings>
</configuration>

Now all you need to do is read from the config file:

string dbPath = System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"]; string email =   System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];

You can use a shortcut by having using System.configuration at the top of the file and just add in the string variables.

It is important to note that in VB.NET, you have to use () instead of [] so it would be:

Dim dbPath as String = ConfigurationSettings.AppSettings("DatabasePath")
Dim email as String = ConfigurationSettings.AppSettings("SupportEmail")

Hi Zorted,

Thanks for you reply, I probably phrased it badly because I've been using these settings already - what I wanted to do was to manually set the Location of the xml file - i.e. which folder it sits in on the disk, rather than the default in the user's profile.

Sadly, I've had to abandon the project and look for a commercial solution after getting 90% there and much extensive work searching forums etc for solutions on another issue - which indicates that it isn't viable (i.e. it's not possible to clear cookies via VB 2008 - or if it is, no-one has sen any working code! :))

Once again, thansk for the reply - A.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.