How to remove the Add New Item Option from a XsltListViewWebPart

Posted on

Unfortunately, XslListViewWebpart does not have a method to make it disappear, it has to be done using reflection, which of course is not supported.

I tried many ways I found on the forums and the only one that works fine is:


Here is my code:

#region Remove the toolbar.
MethodInfo ensureViewMethod = lvwpOrganisation.GetType().GetMethod(“EnsureView”, BindingFlags.Instance | BindingFlags.NonPublic);
object[] ensureViewParams = { };
ensureViewMethod.Invoke(lvwpOrganisation, ensureViewParams);
FieldInfo viewFieldInfo = lvwpOrganisation.GetType().GetField(“view”, BindingFlags.NonPublic | BindingFlags.Instance);
SPView spview = viewFieldInfo.GetValue(lvwpOrganisation) as SPView;
Type[] toolbarMethodParamTypes = { Type.GetType(“System.String”) };
MethodInfo setToolbarTypeMethod = spview.GetType().GetMethod(“SetToolbarType”, BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
object[] setToolbarParam = { “None” }; //set the type here
setToolbarTypeMethod.Invoke(spview, setToolbarParam);





2 thoughts on “How to remove the Add New Item Option from a XsltListViewWebPart

    rinoleboffe said:
    February 4, 2014 at 11:08 am

    when i execute spview.Update();
    return this exception:
    Operation is not valid due to the current state of the object.
    And the toolbar not hide.


    Olaf Hengesbach said:
    May 28, 2015 at 2:03 pm

    In case someone stumbles upon this – there is an easier way: the toolbar is defined in the view XML which is accessible via GetViewXml(). It can be done in an almost-one-liner:

    selectedView.SetViewXml(selectedView.GetViewXml().Replace(“”, “”));

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s