5

I recently successfully added a web-part to the frontpage using the method from Add Document Library XsltListViewWebPart using CSOM or web services

However, it seems impossible to disable the toolbar of this webpart. I have tried adding it to the webpart properties like

     <webParts>
         <webPart xmlns='http://schemas.microsoft.com/WebPart/v3'>
             <metaData>
             <type name='Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'/>
             <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
              </metaData>
              <data>
              <properties>
              <property name='DisableViewSelectorMenu' type='boolean'>true</property>
              <property name='InplaceSearchEnabled' type='boolean'>false</property>
              <property name='ListUrl' type='string'>ProjectInfo</property>
              <property name='Toolbar Type' type ='string'>None</property>
              <property name='MissingAssembly' type='string'>Cannot import this Web Part.</property>
              </properties>
              </data>
              </webPart>
           </webParts>

Or through the code using

WebPart importingWebPart = mgr.ImportWebPart(webPartXml).WebPart; // take webPartXml from above
WebPartDefinition wpDefinition = mgr.AddWebPart(importingWebPart, "Top", 1);
mgr.Context.Load(wpDefinition,d => d.Id); // Id of the hidden view which gets automatically created
mgr.Context.ExecuteQuery();
var viewId = wpDefinition.Id;

List list = web.Lists.GetByTitle("MyLibrary");
View view = list.Views.GetById(viewId);
view.Toolbar = "<Toolbar Type='None'/>"
view.Update();
web.Context.ExecuteQuery();

But nothing works, it keeps happily displaying the toolbar. Yet if i try set the toolbar of a normal view this way, it works instantly.

[Edit] It should be noted that i can modify all other settings of the view this way, just not the toolbar. I can sort, order, add viewfields

Does anyone have a solution?

1

The webpart doesn't has any property for setting Toolbar Type but the view does. You can use CSS or JSLink (postRender Handler) to remove/hide toolbar.

You CSOM seems to be updating the view in the list/library but not necessarily the view on your page.

  • 1
    Updating the query and viewfields of the view in this manner does work though. Its only the toolbar property that is disregarded – Oaden Jul 16 '14 at 7:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.