Add calendar summary view list view webpart


Hi,

Sometimes client asked to add list view web part on the home page of the site. Its easy to add this view just by user interface with some little configuration changes. But using the feature you must know the trick to get the summary view of the calender list. Use following code just create a summary view of the list.

var calendarlist = web.Lists.TryGetList("Calender");
var webpart = new ListViewWebPart
{
ListName = calendarlist.ID.ToString("B").ToUpper(),
ViewGuid = calendarlist.Views[string.Empty].ID.ToString("B").ToUpper()// Use //String.Empty if you are using SP 2007.
};
manager.AddWebPart(webpart, "Middle", 3);

Few more things you can perform if you want to do some more modifications in the view

1) To get the BaseViewId ‘0’ simple use the following code:

var webpart = new ListViewWebPart
{
ListName = calendarlist.ID.ToString("B").ToUpper()
};
var view = calendarlist.GetUncustomizedViewByBaseViewId(0);

2) To add a new field like “End Date” to the BaseViewId ‘0’ simple use the following code:

var webpart = new ListViewWebPart
{
ListName = calendarlist.ID.ToString("B").ToUpper()
};
var view = calendarlist.GetUncustomizedViewByBaseViewId(0);
view.ViewFields.Add(corporateCalendarlist.Fields[new Guid("2684f9f2-54be-429f-ba06-76754fc056bf")]);

3) To change the html formating of the view:
var webpart = new ListViewWebPart
{
ListName = calendarlist.ID.ToString("B").ToUpper()
};
var view = calendarlist.GetUncustomizedViewByBaseViewId(0);
view.ViewFields.Add(corporateCalendarlist.Fields[new Guid("2684f9f2-54be-429f-ba06-76754fc056bf")]);
webpart.ListViewXml = view.HtmlSchemaXml.Replace("
", string.Empty);

Hope the above information will be helpfull to make some little modifications in the summary view using the c#.

Happy sharepointing :)..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s