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

Freitag, 25. November 2011

Custom WebPart zu einer WebPartpage hinzufügen

Um ein Custom WebPart zu einer Page hinzuzufügen benötigt man eine Instanz der spezifischen WebPart-Klasse. Steht einem In dem Moment keine Referenz zu entsprechenden Assembly zur Verfügung kann man sich mit Hilfe eines ObjectHandle eine Instanz erzeugen.

Dazu benötigt man den Klassennamen und den kompletten Assembly-Namen

     String typeName = "Klassenname";
     String assemblyName = "Assembly Name");
     ObjectHandle webPartHandle = Activator.CreateInstance(assemblyName, typeName);
     WebPart webPart =  (WebPart)webPartHandle.Unwrap();
     webParts[0].GetFormattedValue("WebPartTypeName")

Die Werte für typeName und Assembly können auch über eine Query auf die WebPartGallery ermittelt werden
    
    SPQuery query = new SPQuery();
    query.Query = string.Format("{0}", webpartname);
    SPList webPartGallery = this.site.RootWeb.GetCatalog(SPListTemplateType.WebPartCatalog);
    SPListItemCollection webParts = webPartGallery.GetItems(query);
    String typeName =webParts[0].GetFormattedValue("WebPartTypeName"); 
    String assemblyName = webParts[0].GetFormattedValue("WebPartAssembly");

   

Montag, 21. November 2011

WebPart Audience


Der string für WebPart.AuthorizationFilter setzt sich wie folgt zusammen:


string[] globalAudienceIDs = new string[] {"e4687e64-c9d8-4860-bbc3-ec036bf9915d"};
string[] dlDistinguishedNames = new string[] {"cn=group1,cn=users,dc=spdev,dc=com", "cn=group2,cn=users,dc=spdev,dc=com"};  
string[] sharePointGroupNames = new string[] {"Demo Members", "Demo Owners"};  
               
string result = string.Format("{0};;{1};;{2}",  
                                    string.Join(",", globalAudienceIDs),  
                                    string.Join("\n", dlDistinguishedNames),  
                                    string.Join(",", sharePointGroupNames));

d.h. soll eine Sharepoint Gruppe hinzugefügt werden sieht der string wie folgt aus :
";;;;Gruppenname" bzw.
";;;;Gruppenname1, Gruppenname2" 



von
Lapointe Blog -Eintrag

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.