void InitializeFormFields()
        {
            try
            {
                Guid siteGuid = string.IsNullOrEmpty(SPSiteSelector.CurrentId) ? Guid.Empty : new Guid(SPSiteSelector.CurrentId);
                AdministrationConfiguration configuration = SlkAdministration.LoadConfiguration(siteGuid);

                TxtDatabaseServer.Text       = configuration.DatabaseServer;
                TxtDatabaseName.Text         = configuration.DatabaseName;
                ChkCreateDatabase.Checked    = configuration.CreateDatabase;
                TxtInstructorPermission.Text = configuration.InstructorPermission;
                TxtLearnerPermission.Text    = configuration.LearnerPermission;
                TxtObserverPermission.Text   = configuration.ObserverPermission;
                ChkCreatePermissions.Checked = configuration.CreatePermissions;
            }
            catch (SafeToDisplayException ex)
            {
                // exception that's safe to show to browser user
                LabelErrorMessage.Text = Html(ex.Message);
            }
            catch (Exception ex)
            {
                // exception that may contain sensitive information -- since the user is an
                // administrator, we'll show them the error
                LabelErrorMessage.Text = Html(ex.ToString());
            }
        }
    /// <summary>
    /// Configures a SharePoint site collection for use with SLK.
    /// </summary>
    ///
    /// <param name="siteCollectionUrl">The URL of the site collection to configure.</param>
    ///
    static void ConfigureSiteCollectionForSlk(string siteCollectionUrl, string databaseServer,
                                              string databaseName)
    {
        Console.WriteLine("Configuring site collection \"{0}\" for use with SLK",
                          siteCollectionUrl);

        // set <sharePointLocation> to the path to the installation location of SharePoint
        string sharePointLocation;

        using (RegistryKey registryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                   @"Software\Microsoft\Shared Tools\Web Server Extensions\12.0"))
        {
            object value;
            if ((registryKey == null) || ((value = registryKey.GetValue("Location")) == null))
            {
                throw new Exception("SharePoint is not installed");
            }
            sharePointLocation = value.ToString();
        }

        // set <slkAdminLocation> to the path where SLK administration files are located
        string slkAdminLocation = Path.Combine(sharePointLocation,
                                               @"Template\Admin\SharePointLearningKit");

        if (!Directory.Exists(slkAdminLocation))
        {
            throw new Exception("SharePoint Learning Kit is not installed");
        }

        using (SPSite spSite = new SPSite(siteCollectionUrl))
        {
            AdministrationConfiguration configuration = SlkAdministration.LoadConfiguration(spSite.ID);

            if (databaseServer == "CurrentOrDefaultServer")
            {
                databaseServer = configuration.DatabaseServer;
            }
            else
            if (databaseServer == "localhost")
            {
                databaseServer = spSite.HostName;
            }
            if (databaseName == "CurrentOrDefaultDatabase")
            {
                databaseName = configuration.DatabaseName;
            }

            // load SlkSchema.sql, the SQL Server schema for SLK
            string schemaFileContents;
            if (configuration.CreateDatabase)
            {
                schemaFileContents = File.ReadAllText(Path.Combine(slkAdminLocation, "SlkSchema.sql"));
                Console.WriteLine("...database doesn't exist -- creating it");
            }
            else
            {
                schemaFileContents = null; // don't create a database -- it already exists
                Console.WriteLine("...database exists already");
            }

            // load SlkSettings.xml, the default SLK Settings
            string settingsFileContents = File.ReadAllText(
                Path.Combine(slkAdminLocation, "SlkSettings.xml.dat"));

            // save the SLK configuration for this SPSite
            SlkAdministration.SaveConfiguration(spSite.ID, configuration.DatabaseServer, configuration.DatabaseName,
                                                schemaFileContents, configuration.InstructorPermission, configuration.LearnerPermission, configuration.ObserverPermission, configuration.CreatePermissions,
                                                null, settingsFileContents, spSite.WebApplication.ApplicationPool.Username);
        }
    }