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:

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/a4b27730-dd81-4ff6-8003-a002a2fdec88

 

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);
spview.Update();
#endregion

 

 

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s