Specifying the “Start Date” and “Calendar Period” in the URL to a SharePoint calendar using Out-of-the-Box functionality

2 Comments

A friend asked me if there was a way to specify the start date for a calendar in SharePoint. The specific use case involved sending users to a shared SharePoint calendar and allowing them to list the events they are attending at a convention. The convention exists in the future, but upon navigating to the calendar, users are taken to today’s date. As such, users had to navigate to the date of the convention and then schedule their events.

SharePoint does not provide a way to limit the range of calendar events out-of-the-box. Like all things SharePoint, the calendar is a list; however, items in the list are displayed on top of an existing layer of data, or the pre-determined collection of “allowed” calendar dates, which consists of 365 days in each year, etc.

While there is no way to create a calendar in which this “allowed dates” set can be limited (without custom development), there is a way to send users directly to a specific date by modifying the URL to the calendar.

The default calendar URL looks something like this:

http://MySharePointSite/Lists/Calendar/calendar.aspx

By adding the following to the URL, you can specify the date range to show the user, as well as the “time period” (month/week/day) to display:

http://MySharePointSite/Lists/Calendar/calendar.aspx?CalendarDate=10/10/2011&CalendarPeriod=week

 

SharePoint Calendar

The aforementioned URL would direct the user to this view of the calendar.

Note: Query string parameters are added following a question mark (?); if more than one parameter is specified, additional parameters must be separated by an ampersand (&).

Placing a similarly-constructed URL on the Quick Launch sidebar gives us a way to quickly send users to a specific date range on the calendar list, and fits our use case quite nicely in that the calendar itself is not modified, but the user is directed to the dates on which the conference takes place.

Note that specifying “week” as the CalendarPeriod parameter will automatically display the work week to which the CalendarDate parameter belongs.  To modify the day/hour range of a standard work week, modify the Regional Settings from the Site Settings page.

Setting the “Job Description” of a Custom SharePoint Timer Job [SOLVED]

2 Comments

This post has been edited.  See the end of the post for the thrilling conclusion.

I wanted to set the “Job Description” property of a custom SharePoint Timer Job, because it was not appearing on the “Edit Timer Job” screen in SharePoint Central Admin:

"Job Description" is missing.

If you try to set the “Description” property of your timer job in the constructor, you’ll notice that “Description” is a read-only property of the SPJobDefinition class.

As my colleague pointed out, this “Description” property is a virtual property, as noted in the class description on MSDN:

//MSDN definition of SPJobDefinition.Description property
public virtual string Description { get; }

But you cannot simply override it in your timer job class (which is a subclass of SPJobDefinition) as such, because there is no definition for a ‘set’ accessor:

//Override Description property-- doesn't work
public override string Description
{
     get;
     set;
}

Curious, as was I, my colleague disassembled the SharePoint.dll assembly, and what do you know, the ‘get’ accessor is written to return an empty string (hence the inclusion of the ‘virtual’ keyword to encourage overriding the base accessor):

//Disassembled SharePoint.dll SPJobDefinition class
public virtual string Description
{
     get
     {
      return string.Empty;
     }
}

I also tried creating my own CustomDescription property in my class that inherits from SPJobDefinition and overriding the ‘get’ accessor of the base Description property to return the value of CustomDescription:

//Custom Job Description
private string CustomDescription
{
    get;
    set;
}

// Override built-in Description property by returning our custom description in the getter accessor
public override string Description
{
    get
    { return CustomDescription; }
}

Then I set the value of CustomDescription in the constructor (EDIT: do this in ALL THREE constructors!):

//Constructor for custom timer job class that inherits from SPJobDefinition
public MyTimerJob(string jobName, string jobDescription, SPWebApplication webApplication)
     : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
{
    this.Title = jobName;
    CustomDescription = jobDescription;
}

No dice.

Here’s the link to the MSDN thread where the same question was supposedly answered; I found this thread following the initial publication of this post, and it looks like we both tried the same thing.  We’ll see if I hear back.

I’m not really sure where to go from here.  It looks as though this “Description” property is set for OOB SharePoint timer jobs only, and there’s nothing we can do about it.  Unless, of course, you can set a timer job’s description from stsadm or a PowerShell script…

Turns out you have to set the CustomDescription in ALL THREE constructors.  Why?  Because even though I’m calling my custom constructor to create the timer job, SharePoint actually calls the base constructor.  Attach to the process if you don’t believe me :)

Follow

Get every new post delivered to your Inbox.