Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi Team,
I am generating setup for window service.
I want to give option to user to mention all config level data on UI at the time of setup installation.
By referring no of sites I am able to achieve that expected output, but there are some moification.
I am able to show label and text box and bind that value by referring some below link.
Customize User Interfaces and Pass User Input to Installer Classes[^]

ScottGu's Blog - Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005[^]

Expection is:
1)I want to do validation means user will be not able to click on next button by keeping empty text box.
2)Now user mentioning data into text box normally, instead of that I want to give browse button to select path and fill text box.

What I have tried:

This is code that I am using for showing and binding text box value.
C#
 [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            try
            {
                AddConfigurationFileDetails();
            }
            catch (Exception e)
            {              
                base.Rollback(savedState);
            }
        }

        private void showParameters()
        {
            StringBuilder sb = new StringBuilder();
            StringDictionary myStringDictionary = this.Context.Parameters;
            if (this.Context.Parameters.Count > 0)
            {
                foreach (string myString in this.Context.Parameters.Keys)
                {
                    sb.AppendFormat("String={0} Value= {1}\n", myString,
                    this.Context.Parameters[myString]);
                }
            }
        }

        private void AddConfigurationFileDetails()
        {
            try
            {
                string LogFilePath = Context.Parameters["LogFilePath"];
                string Customer_Input_Filepath = Context.Parameters["Customer_InputFilePath"];
                string ServerPublicKeyPath = Context.Parameters["ServerPublicKeyPath"];
                string ClientPrivateKeyPath = Context.Parameters["ClientPrivateKeyPath"];
                string ClientPrivateKeyPassword = Context.Parameters["ClientPrivateKeyPassword"];
                string SFTP_IN_PATH = Context.Parameters["SFTP_IN_PATH"];
                string SFTP_OUT_PATH = Context.Parameters["SFTP_OUT_PATH"];

                string HostName = Context.Parameters["HostName"];
                string PortNo = Context.Parameters["PortNo"];
                string UserName = Context.Parameters["UserName"];
                string CertificateKeyFilePath = Context.Parameters["CertificateKeyFilePath"];
                string PassPhrase = Context.Parameters["PassPhrase"];

                // Get the path to the executable file that is being installed on the target computer  
                string assemblypath = Context.Parameters["assemblypath"];
                string appConfigPath = assemblypath + ".config";

                // Write the path to the app.config file  
                XmlDocument doc = new XmlDocument();
                doc.Load(appConfigPath);

                XmlNode configuration = null;
                foreach (XmlNode node in doc.ChildNodes)
                    if (node.Name == "configuration")
                        configuration = node;

                if (configuration != null)
                {
                    //MessageBox.Show("configuration != null");  
                    // Get the ‘appSettings’ node  
                    XmlNode settingNode = null;
                    foreach (XmlNode node in configuration.ChildNodes)
                    {
                        if (node.Name == "appSettings")
                            settingNode = node;
                    }

                    if (settingNode != null)
                    {
                        //MessageBox.Show("settingNode != null");  
                        //Reassign values in the config file  
                        foreach (XmlNode node in settingNode.ChildNodes)
                        {
                            //MessageBox.Show("node.Value = " + node.Value);  
                            if (node.Attributes == null)
                                continue;
                            XmlAttribute attribute = node.Attributes["value"];
                            //MessageBox.Show("attribute != null ");  
                            //MessageBox.Show("node.Attributes['value'] = " + node.Attributes["value"].Value);  
                            if (node.Attributes["key"] != null)
                            {
                                //MessageBox.Show("node.Attributes['key'] != null ");  
                                //MessageBox.Show("node.Attributes['key'] = " + node.Attributes["key"].Value);  
                                switch (node.Attributes["key"].Value)
                                {

                                    case "Test":
                                        attribute.Value = Convert.ToString(LogFilePath.Replace("\\", @"\"));
                                        break;
                                    case "LogFilePath":
                                        attribute.Value = Convert.ToString(LogFilePath.Replace("\\", @"\"));
                                        break;

                                    case "Customer_InputFilePath":
                                        attribute.Value = Convert.ToString(Customer_Input_Filepath.Replace("\\", @"\"));// + "\\";
                                        break;

                                    case "ServerPublicKeyPath":
                                        attribute.Value = ServerPublicKeyPath;
                                        break;

                                    case "ClientPrivateKeyPath":
                                        attribute.Value = ClientPrivateKeyPath;
                                        break;

                                    case "ClientPrivateKeyPassword":
                                        attribute.Value = ClientPrivateKeyPassword;
                                        break;

                                    case "SFTP_IN_PATH":
                                        attribute.Value = SFTP_IN_PATH;
                                        break;

                                    case "SFTP_OUT_PATH":
                                        attribute.Value = SFTP_OUT_PATH;
                                        break;

                                    case "HostName":
                                        attribute.Value = HostName;
                                        break;

                                    case "PortNo":
                                        attribute.Value = PortNo;
                                        break;

                                    case "UserName":
                                        attribute.Value = UserName;
                                        break;

                                    case "CertificateKeyFilePath":
                                        attribute.Value = CertificateKeyFilePath;
                                        break;

                                    case "PassPhrase":
                                        attribute.Value = PassPhrase;
                                        break;
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(CertificateKeyFilePath))
                    {
                        doc.Save(appConfigPath);
                    }
                    else
                    {
                        
                    }
                }
            }
            catch
            {
                throw;
            }
        }  
    }
	Please give me solution for validation and browse button
Please reply as soon as possible.




Please give me solution for validation and browse button
Please reply as soon as possible.
Posted
Updated 5-May-17 1:45am

1 solution

Use the LostFocus on your textbox.

private void textbox_LostFocus(object sender, EventArgs e)
{
   //do something to validated the textbox value 
   if (textbox.text = "") 
   {
      btncancel.Enabled = false;
      //if not filled you can directly setfocus on box again so the user can't leave it.
      this.ActiveControl = textbox
   }

   //or do whatever you want...
}
 
Share this answer
 
v2
Comments
Member 12597032 5-May-17 9:42am    
How I can disable next button..?
btncancel.isenabled=false;
this code is not working..

please give ans in brief..
Wessel Beulink 5-May-17 9:46am    
btncancel.isenabled is a return value. Ofcourse that's not working.
Use btncancel.enabled = false when txtbox.text = "".
Wessel Beulink 5-May-17 9:54am    
Updated solution for you.
Member 12597032 5-May-17 10:04am    
Hello,

I am taking textboxes when creating setup which are like Textboxes(A),Textboxes(B), Textboxes(C) ?....Inside all this section there are 4 text boxes each.....how can i generate event for these textboxes ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900