Rick van den Bosch - Blog

... on .NET, software architecture, software development and whatnot

Recent Posts

Tags

News

  • Live space

    Photo blog

    Follow me at twitter

    Rick  van den Bosch

    LinkedIn profile

    Add to Technorati Favorites

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Community

Email Notifications

Blogs I read

Interesting links

Archives

January 2006 - Posts

HowTo: read your configfile when using no-touch deployment

Earlier I posted about reading a configfile when using no-touch deployment. Several people have contacted me to post the code, so here it is.

private static bool InitializeRemoting()
{
    string configFile;

    configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
    try
    {
        //try to read the configfile without tricks first
        RemotingConfiguration.Configure(configFile);
    }
    catch (RemotingException)
    {
        //When 'normal' reading fails, try it our special way.
       
string tempDir;
        WebClient webClient;

        //Get the location of the application data folder
        tempDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        tempDir +=
@"\ApplicationName\";
        if (!Directory.Exists(tempDir))
        {
            //Add a folder for our own application
            Directory.CreateDirectory(tempDir);
        }
       
try
       
{
            //Download the configfile to the new folder and use it to configure Remoting
            webClient =
new WebClient();
            webClient.DownloadFile(configFile, tempDir +
"ApplicationName.exe.config");
            RemotingConfiguration.Configure(tempDir +
"ApplicationName.exe.config");
        }
       
catch
       
{
           
return false;
        }
    }
    return true;
}