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);





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