views:

147

answers:

1

Does anyone know if it's possible to display items on a calendar view (on a document library) in SharePoint based on properties of a folder (which is a custom content type in itself) rather than for the files in the document library.

For example:

Folder1 Expires=20/4/2010 Folder2 Expires=21/4/2010

For these folders, there should be two items on the calendar view only for the dates that the Expires property is set to.

I've tried to configure this via the UI with no luck (calendar views always list files, rather than folders, even normal folders). I have no idea where to start with trying this in C# (can't find much on the web).

+1  A: 

By default, a calendar view is setup to only display files/list items, and there is no way to change this via the UI.

However, I did a quick test and it seems you can tweak the view using code so that it will also display folders.

Here's a sample of the code you need

//open the site and web
using(SPSite site = new SPSite("http://urltosite"))
{
    using(SPWeb web = site.OpenWeb())
    {
       //get the document library and calendar view
       SPList docLib = web.Lists["Documents"];
        SPView view = docLib.Views["CalendarView"];

        //set the view scope to recursive all (default is Recursive)
        view.Scope = SPViewScope.RecursiveAll;
        view.Update();
    }
}

Hope that helps

Paul Lucas