SharePoint. What can you say about it? Among other things, it's designed to help you manage and present content. It's supposed to make things easy for you. If you want some customization, just write some code to do whatever and configure it to run at the appropriate time for the appropriate page(s).

Of course, this leaves open the possibility that folks who may be something less than experts might author said customizations.

Paul is responsible for numerous customizations written by developers long gone from their project. One particular customization was to perform some clean up. At first, it was run once per day. Over time, that grew to running 8+ times per day on each of several servers.

One day, the customization stopped working. Naturally, there was no record of it anywhere in source control (thank you predecessor coders).

Having no alternative, the code was decompiled into the following loveliness:

private static void Main(string[] args) {
  using (SPSite site = new SPSite("<SITE ANONYMOUS>")) 
  {
    using (SPWeb web = site.OpenWeb())
    {
      SPList list = web.Lists["Calendar"];
      site.AllowUnsafeUpdates = true;
      try {
          foreach (SPListItem item in list.Items) {
            DateTime now   = DateTime.Now;
            DateTime time2 = now.AddDays(30.0);
            DateTime time3 = (DateTime) item["End Time"];
            DateTime time4 = (DateTime) item["Start Time"];
            DateTime time5 = time3;
            DateTime time6 = time4;
            DateTime time7 = now;
            DateTime time8 = time2;
            if (time3 >= now) {
               if ((time5 >= time7) && (time6 <= time8)) {
                  item["DisplayThis"] = "YES";
                  item.Update();
               } else {
                  item["DisplayThis"] = "NO";
                  item.Update();
               }
            } else if (time3 < now) {
              item["DisplayThis"] = "NO";
              item.Update();
            }
          }
      } catch (Exception) {
      } finally {
        site.AllowUnsafeUpdates = false;
      }
    }
  }
}

There seem to be three different ways to refer to DateTime.Now, and eight variables that could easily be knocked down to...none.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!