3

I'm currently using Sharepoint 2016. I added a document library XsltListViewWebPart into my page using C#. I am trying to remove the toolbar. First i did this:

myWebPat.Toolbar = "None";

Nothing happen. Then i tried the following:

//Set toolbar type to None
MethodInfo ensureViewMethod = lvwp.GetType().GetMethod("EnsureView", BindingFlags.Instance | BindingFlags.NonPublic);
object[] ensureViewParams = { };
ensureViewMethod.Invoke(lvwp, ensureViewParams);
FieldInfo viewFieldInfo = lvwp.GetType().GetField("view", BindingFlags.NonPublic | BindingFlags.Instance);
SPView spView = viewFieldInfo.GetValue(lvwp) as SPView;
Type[] toolbarMethodParamTypes = { Type.GetType("System.String") };
MethodInfo setToolbarTypeMethod = spView.GetType().GetMethod("SetToolbarType", BindingFlags.Instance | BindingFlags.NonPublic, null, toolbarMethodParamTypes, null);
object[] setToolbarParam = { "None" };
setToolbarTypeMethod.Invoke(spView, setToolbarParam);

But i hit error at:

FieldInfo viewFieldInfo = lvwp.GetType().GetField("view", BindingFlags.NonPublic | BindingFlags.Instance);
SPView spView = viewFieldInfo.GetValue(lvwp) as SPView;

The error message is:

The object is not set to an instance of an Object.

Apparently, the viewFieldInfo gives me null value.

Is there any other approach?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.