//
Add a webpart programatically in a easy manner J
Today I managed to do it!!!!!!!
This
is very useful if we are going to add Events, Forum(Discussion
board), Tasks list into our page with the OOB features.
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
//am creating a Task listGuid WorkflowHistoryGuid = web.Lists.Add(ConfigurationInfo.Tasks, ConfigurationInfo.Tasks,SPListTemplateType.Tasks);
SPList TaskList = web.Lists[ConfigurationInfo.Tasks];
TaskList.OnQuickLaunch = true;TaskList.Update();
//actual
work starts
SPList taskList = web.Lists[ConfigurationInfo.Tasks];
SPView viewMyTasks = taskList.Views[“My Tasks”];
viewMyTasks.DefaultView = true;
viewMyTasks.Update();
taskList.Update();
webPart.ListName = taskList.ID.ToString("B").ToUpper();
webPart.ViewGuid = taskList.DefaultView.ID.ToString("B").ToUpper();
wpm.AddWebPart(webPart,"MiddleRightZone", 2);
}
No comments:
Post a Comment