+ Reply to Thread
Results 1 to 2 of 2

Thread: Method to check the expiration date of a license file

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    8

    Method to check the expiration date of a license file

    I have created license files inside xml format :
    Code:
    <License>
    <Expire-Date>03/23/2012</Expire-Date>
    </License>
    Then how to compare the current date with that date in license file so in case the Date on Expire-Date has passed the Application should give an error : License Expired. ?
    Last edited by wilson; 11-08-2012 at 11:03 PM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Here would be the right code :
    Code:
                    
                using System.Xml;
    
    
                XmlDocument xml = new XmlDocument();
                xml.Load("FIlename.xml");
    
                XmlNodeList nodes = xml.SelectNodes("//License");
    
                foreach (XmlNode node in nodes)
                {
                    // date format : MM/dd/yyyy
                    string[] get_expireyear = node.SelectSingleNode("Expire-Date").InnerText.Split('/');
                    int counter1 = 0;
                    foreach (string current_expire_year in get_expireyear)
                    {
                        counter1++;
                        if (counter1 == 3)
                        {
                            if (Convert.ToInt16(current_expire_year) >= Convert.ToInt16(DateTime.Now.ToString("yyyy")))
                            {
                                if (Convert.ToInt16(current_expire_year) == Convert.ToInt16(DateTime.Now.ToString("yyyy")))
                                {
                                    string[] get_expiremonth = node.SelectSingleNode("Expire-Date").InnerText.Split('/');
                                    int counter2 = 0;
                                    foreach (string current_expire_month in get_expiremonth)
                                    {
                                        counter2++;
                                        if (counter2 == 1)
                                        {
                                            if (Convert.ToInt16(current_expire_month) >= Convert.ToInt16(DateTime.Now.ToString("MM")))
                                            {
                                                if (Convert.ToInt16(current_expire_month) == Convert.ToInt16(DateTime.Now.ToString("MM")))
                                                {
                                                    string[] get_expireday = node.SelectSingleNode("Expire-Date").InnerText.Split('/');
                                                    int counter3 = 0;
                                                    foreach (string current_expire_day in get_expireday)
                                                    {
                                                        counter3++;
                                                        if (counter3 == 2)
                                                        {
                                                            if (Convert.ToInt16(current_expire_day) >= Convert.ToInt16(DateTime.Now.ToString("dd")))
                                                            {
                                                                if (Convert.ToInt16(current_expire_day) == Convert.ToInt16(DateTime.Now.ToString("dd")))
                                                                {
                                                                    MessageBox.Show("Your License Has expired!");
                                                                    Application.Exit();
                                                                }
                                                            }
                                                            else
                                                            {
                                                                MessageBox.Show("Your License Has expired!");
                                                                Application.Exit();
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show("Your License Has expired!");
                                                Application.Exit();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Your License Has expired!");
                                Application.Exit();
                            }
                        }
                    }
                }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts