添加具有SharePoint 2010和摘要视图的日历Web部件

时间:2010-09-08 18:35:14

标签: sharepoint-2010

我正在尝试将日历Web部件添加到功能中的default.aspx页面。日历放在表单上,​​但我希望默认视图是摘要视图。我已经读过,如果您将ViewGuid设置为string.Empty,它会将视图设置为摘要视图,但这不起作用。

想法?

//  Calendar
ListViewWebPart calendarWP = new ListViewWebPart();
SPList calendarList = site.Lists["Calendar"];
calendarWP.ListName = calendarList.ID.ToString("B").ToUpper();
calendarWP.ViewGuid = string.Empty;
oWPManager.AddWebPart(calendarWP, "Left", 3);

1 个答案:

答案 0 :(得分:1)

经过一些挖掘和实验,我找到了解决这个谜团的方法。

Sharepoint 2007(我认为这适用于2007年)

SPList calendarList = site.Lists["Calendar"]; 
calendarWP.ListName = calendarList.ID.ToString("B").ToUpper(); 
calendarWP.ViewGuid = string.Empty; 
oWPManager.AddWebPart(calendarWP, "Left", 3);

Sharepoint 2010

SPList calendarList = site.Lists["Calendar"]; 
calendarWP.ListName = calendarList.ID.ToString("B").ToUpper(); 

SPView summaryView = calendarList.Views[string.Empty];
calendarWP.ViewGuid = summaryView.ID.ToString("B").ToUpper();
oWPManager.AddWebPart(calendarWP, "Left", 3);

希望这有助于其他人