0
votes

After working long for the creating the installer for my application using http://wixtoolset.org/ and i am using 3.10v,finally i got the working .msi installer file.

But i wanted the list of websites that are present in IIS server to be display in the dropdown list during installation, so that i can select the existing website from the IIS server and use that to install my application.

I created a ComboBox Control in my UI page (.wxs file), and stuck at writing the custom action, any Help Greatly appreciate!!

1

1 Answers

1
votes

Just add a custom action like this:

  <CustomAction Id="GetIISWebsitesID" BinaryKey="GetIISWebsites" DllEntry="CustomAction1" Execute="immediate" Return="check"></CustomAction>
  <Binary Id="GetIISWebsites" SourceFile="..\GetIISWebsites\bin\Debug\GetIISWebsites.CA.dll"/>

in your wxs file and the code for Custom Action is below:

namespace GetIISWebsites
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session xiSession)
        {
            System.Diagnostics.Debugger.Launch();
            Microsoft.Deployment.WindowsInstaller.View lView = xiSession.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='xxxxxxxx'");
            lView.Execute();

            lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
            lView.Execute();
            List instances = RetrieveIISWebsites();
            int Counter = 0;
            int Index = 0;
            bool flag = false;
            try
            {
                foreach (string str in instances)
                {
                    Record lRecord = xiSession.Database.CreateRecord(4);
                    lRecord.SetString(1, "xxxxxxxx");
                    lRecord.SetInteger(2, Index);
                    lRecord.SetString(3, str);
                    lRecord.SetString(4, str);
                    lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
                    Counter = Index;
                    ++Index;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                xiSession.Log("Exception Details: " + ex.Message);
            }
            lView.Close();

            xiSession.Log("Closing view");
            lView.Close();
            return ActionResult.Success;
        }
        private static List RetrieveIISWebsites()
        {
            List result = new List();
            var websites = GetSites();
            foreach (Site site in websites)
            {
                result.Add(site.Name);
            }

            return result;
        }
        private static SiteCollection GetSites()
        {
            var iisManager = new ServerManager();
            SiteCollection sites = iisManager.Sites;
            return sites;
        }
    }
}

here xxxxxxxx is the property binded to Combo box.

add Microsoft.Web.Administration.dll from your C:\Program Files (x86)\WiX Toolset v3.9\bin folder.

Let me know if answered correctly or you have any doubt.