protected override void CreateChildControls() { Label timeRemaining = new Label(); this.Controls.Add(timeRemaining); timeRemaining.CssClass = "wbf-time-to-auto-close"; try { WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current); if (workBox != null) { DateTime endTime = workBox.calculateAutoCloseDate(); if (endTime.Year == WBRecordsType.YEAR_REPRESENTING_A_PERMANENT_DATE) { timeRemaining.Text = "This work box will not auto close."; } else { if (endTime < DateTime.Now) { timeRemaining.Text = "No time remaining before auto close."; } else { TimeSpan timeSpan = endTime - DateTime.Now; timeRemaining.Text = String.Format("{0} Days {1} Hours {2} Minutes", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes); } } workBox.Dispose(); } else { timeRemaining.Text = "You can only use this web part on a work box."; } } catch (Exception e) { WBLogging.Generic.Unexpected("Error: " + e.Message); timeRemaining.Text = "An error occurred"; } }