Share via


Custom toolbar of a SPView object on SPLite

Currently I’m in an engagement where I have to show the custom toolbar on a list view.

I started my code to create a new SPView and attach the same one with SPList, I’m able to change query, title etc properties of view. But once I started to change ToolBarType I was fail as it is a readonly property.

So I went to use a unsupported way to achieve the same, here is my code.

privatestaticvoid CustomToolbar( SPView view)

{

PropertyInfo nodeProp = spView.GetType().GetProperty( "Node" ,  BindingFlags.NonPublic | BindingFlags.Instance);

 

XmlNode node = nodeProp.GetValue(spView, null ) asXmlNode ;

XmlNode toolBarNode = node.SelectSingleNode( "Toolbar" );

 

if (toolBarNode!= null )

   {

XmlAttribute typeNode = toolBarNode.Attributes[ "Type" ];

      toolBarNode.RemoveAll();

      toolBarNode.Attributes.Append(typeNode);

      typeNode.Value = "None" ;

    }

  view.ToolBar = “<IfHasRights><RightsChoices><RightsGroup PermAddListItems='required' /></RightsChoices><Then><HTML><![CDATA[ <table onmouseover='' class='ms-menutoolbar' cellpadding='2' cellspacing='0' border='0' width='100%'> <tr> <td class='ms-toolbar' nowrap='true'> <span title='Log a Request'> <table height='100%' cellspacing='0' class='ms-splitbutton' hoveractive='ms-splitbuttonhover' hoverinactive='ms-splitbutton' downarrowtitle='Log a Request' id='rst' onmouseover='MMU_EcbTableMouseOverOut(this, true)'> <tr> <td valign='middle' class='ms-splitbuttontext' style='cursor: hand; white-space: nowrap;vertical-align: middle' onclick=\"javascript:window.location=']]></HTML><HttpVDir /><HTML><![CDATA[/_layouts/RemoteSME/RemoteSMEPage.aspx]]></HTML><HTML><![CDATA[';javascript:return false;\" >&nbsp;<img style='cursor: hand; white-space: nowrap; vertical-align: middle' src='/_layouts/images/ADDCOL.GIF' alt='Log a Request' />&nbsp;<a id='zz12_NewMenu' accesskey='N' href='#' onclick='javascript:return false;' style='cursor: hand; white-space: nowrap; vertical-align: middle'> Log a Request <img src='/_layouts/images/blank.gif' border='0' /> </a> </td> </tr> </table> </span> </td> <td class='ms-separator'> <img src='/_layouts/images/blank.gif' alt=''> </td> <td width='99%' class='ms-toolbar' nowrap='true'> <img src='/_layouts/images/blank.gif' width='1' height='18' alt='' /> </td> </tr> </table>]]></HTML></Then></IfHasRights>” ;

   view.Update();
}

 OutPut View