Posts mit dem Label ToolbarType werden angezeigt. Alle Posts anzeigen
Posts mit dem Label ToolbarType werden angezeigt. Alle Posts anzeigen

Dienstag, 26. Oktober 2010

How to Add a ListViewWebPart to a Publishing Page

neuer Versuch das ListViewWebPart zu verstehen







Adding a ListViewWebPart to a "Publishing Page" is easy.
Create a Instance of a SPWebpartmanager, with the relevant Page-Url and get the WebPartCollection.
Create a new ListViewWebPart instance, set the ListID to the ID of SPList object you want to show.
Provide a ViewID to the Webpart and add it to the Collection, including the ID of the WebPartZone and a Sequence Number for the order within the zone.


Showing a Document Library including the "Add document" Button  isn't easy at all.
In the UI it is just a click away -> Edit WebPart ->  select ToolbarType and set it to "Summary ToolBar".
I think its almost default in UI.

[UPDATE: see adding-listviewwebpart-to-page]
If you want to use OM to add this WebPart you have to use a "hack" by modifying the schema of the used view. Which can affect also the view of the document library.
Jalil Sear describes it at his blog listviewwebpart-programatically-setting-the-toolbartype-property/


I worked around this issue by adding my own "Add Document" button to the page, having the possibillity of positioning, using audiences and renaming.