开发者

Add Calendar Web Part w/SharePoint 2010 AND Summary View

I am trying to add a calendar web part to the default.aspx page within a feature开发者_开发问答. The calendar gets placed on the form but I would like the default view to be the summary view. I have read that if you set the ViewGuid to string.Empty it will set the view to the summary view but this is not working.

Ideas?

//  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);


After doing some digging and experimenting, I have found the solution to this mystery.

Sharepoint 2007 (I assume this works on 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);

Hope this helps someone else

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜