Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Programmatically created calendar view does not appear on view selector menu

$
0
0

Hi!

I'm using the following code to create a calendar view for a list:

using (var site = new SPSite("http://localhost"))
{
    var viewFields = new System.Collections.Specialized.StringCollection { dateStartFieldName, dateEndFieldName, titleFieldName };

    var query = string.Format("<Where><DateRangesOverlap><FieldRef Name='{0}' /><FieldRef Name='{1}' /><Value Type='DateTime'><Month /></Value></DateRangesOverlap></Where>", dateStartFieldName, dateEndFieldName);
    var viewData = string.Format("<FieldRef Name='{0}' Type='CalendarMonthTitle' /><FieldRef Name='{0}' Type='CalendarWeekTitle' /><FieldRef Name='' Type='CalendarWeekLocation' /><FieldRef Name='{0}' Type='CalendarDayTitle' /><FieldRef Name='' Type='CalendarDayLocation' />", titleFieldName);

    var list = site.RootWeb.Lists["ESM Leaves"];
    var newView = list.Views.Add("Calendar11", viewFields, query, 0, true, false, SPViewCollection.SPViewType.Calendar, false);
    newView.ViewData = viewData;
    newView.MobileView = true;
    newView.Update();

    list.Update();
}

My problem is that even though the view is created, it does not appear in the View links just above my list. It only appears in the drop down menu of views in the ribbon. On the contrary, if I create the view using the browser user interface (not programmatically), the view appears in both places.

Do you have any idea why this might be happening?


Dimitris Papadimitriou, Software Development Professional


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>