Answered by:
Programmatically created calendar view does not appear on view selector menu

Question
-
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
- Edited by papadi Wednesday, March 26, 2014 11:18 AM More appropriate title
Monday, March 24, 2014 2:10 PM
Answers
-
Hi papadi,
I can reproduce the issue that creating calendar view using programming method, the view isn’t shown in view selector menu, and this only happens to calendar view, html view or other views are shown in the menu.
After editing the web part, disable the selector menu, then re-enable the selector menu again, I can see the calendar view shown in the view selector menu, create a new calendar view using programming, the calendar view shows as expected.
This seems indicate there is some issue in the view selector menu display, I would suggest you to first disable the view selector menu through edit the web part properties, then create the calendar view.
Thanks,
Qiao
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Qiao Wei
TechNet Community Support- Marked as answer by papadi Wednesday, March 26, 2014 9:18 AM
Wednesday, March 26, 2014 5:38 AM
All replies
-
Monday, March 24, 2014 2:24 PM
-
I don't see any of these links answering my question. Am I wrong? Have I missed anything? Actually the code I'm using comes from one of them anyway. My problem is a bit specific.
Dimitris Papadimitriou, Software Development Professional
Monday, March 24, 2014 9:11 PM -
Hi papadi,
I can reproduce the issue that creating calendar view using programming method, the view isn’t shown in view selector menu, and this only happens to calendar view, html view or other views are shown in the menu.
After editing the web part, disable the selector menu, then re-enable the selector menu again, I can see the calendar view shown in the view selector menu, create a new calendar view using programming, the calendar view shows as expected.
This seems indicate there is some issue in the view selector menu display, I would suggest you to first disable the view selector menu through edit the web part properties, then create the calendar view.
Thanks,
Qiao
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Qiao Wei
TechNet Community Support- Marked as answer by papadi Wednesday, March 26, 2014 9:18 AM
Wednesday, March 26, 2014 5:38 AM -
Ok, I see that this works even after creating the view. If I edit the page, disable the selector menu and enable it again (without leaving the 'Edit Page' session at all) the link of the view appears.
Annoying! I suppose there is no programmatic way of doing this enabling/disabling of the selector menu. Right?
Dimitris Papadimitriou, Software Development Professional
- Edited by papadi Wednesday, March 26, 2014 9:50 AM
Wednesday, March 26, 2014 9:18 AM -
I'm struggling with the exact same issue (though with a GRID view). Disabling the selector menu manually is not an option unfortunately. Any updates regarding this issue?Wednesday, October 28, 2015 3:18 PM