Helper method to Set the "ShowToolbar" of ListViewWebPart Toolbar
private void SetToolbarType(SPWeb web)
{
try
{
string url = web.Url + "/Pages/defaultlenze.aspx";
SPLimitedWebPartManager splwManager = web.GetLimitedWebPartManager(url, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
SPFile file = splwManager.Web.GetFile(url);
file.CheckOut();
foreach (WebPart webPart in splwManager.WebParts)
{
if (webPart is Microsoft.SharePoint.WebPartPages.ListViewWebPart)
{
Guid webPartGuid = new Guid(((Microsoft.SharePoint.WebPartPages.ListViewWebPart)webPart).ViewGuid);
string listName = string.Empty;
if (webPart.Title == "My Active Task")
{
listName = "Tasks";
}
else if(webPart.Title == "News")
{
listName = "News";
}
SPView view = web.Lists[listName].Views[webPartGuid];
Type[] toolbarMethodParamTypes = { Type.GetType("System.String") };
MethodInfo setToolbarTypeMethod = view.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
object[] setToolbarParam = { "ShowToolbar" }; //set the type here
setToolbarTypeMethod.Invoke(view, setToolbarParam);
view.Update();
}
}
file.CheckIn("");
file.Publish("");
}
No comments:
Post a Comment