Seiten

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

Mittwoch, 8. Februar 2012

ShowInPicker in BCS Model is ignored

Rather than trying to hide TypeDescriptors you need to only apply  ShowInPicker="true" to the ones you want to show. If none of the TypeDescriptors has ShowInPicker=true then all TypeDescriptor are displayed, even if some have ShowInPicker=false


Mittwoch, 23. November 2011

Programmatically populating a BDC field in Sharepoint 2010

In this post I try to explain how to retrieve and store data in a external lookup column or business data field. For the code snippets I use PowerShell instead of C# because I can test my claims as I write.

Lets set up some pseudo vars

$list=$web.Lists["ListWithExternalRef"]
$listItem=$list[0]
$bdcField=$list.Fields["ExternalItemField"]

$listItem["bdcColName"] holds the value of the BDC field which was specified when setting up the column, which can be set in SPBusinessDataField.BdcFieldName. The data is always stored as a string.
The BCS Identity of the item is stored in $listItem[$bdcField.RelatedField]. 
(Still need to check if this is EntityInstanceReference or Identity
Check BCSFieldEditor and ItemPicker with .NET Reflector )

If you want to deserialize the EntityInstanceReference you need to get an instance to the matching IMetadataCatalog :
$bdcService=(Get-SPService).services|?{$_.typename -eq "Business Data Connectivity Service"}
$bdcCat=$bdcService.GetDatabaseBackedMetadataCatalog((Get-SPServiceContext http://yourdevsite))
[Microsoft.BusinessData.Runtime.entityinstancereference]::Deserialize($bcsRef,$bdcCat)


For each additional external column which is stored with this field Sharepoint creates a field in the list. The additional fields names can be obtained with $bdcField.GetSecondaryFieldsNames(). To get a reference to the field you can use the display name which is in the  format "$($bdcField.Title): $secondaryFieldName"

Sharepoint doesnt set the secondary lookup values itself when you save the entry, so you have to retrieve all values for the secondary field names. 

Dienstag, 18. Oktober 2011

Programmatically change Sharepoint list forms

A very common request for a sharepoint developer is to customize the form of a list. With Sharpeoint Designer this is really easy to do but this has the downside that a) designer forms with Sharepoint Designer is harder than it looks and b) it comes with all the downsides of customization vs definition such as not having a deployable solution. Another option is to use InfoPath Designer but this is not cheap because you need Office Pro and the enterprise version of Sharepoint.
The same in object model, please

the same as SPList.Forms
Another, very attractive option is to use ASP.NET markup and code to define the design and functionality of a form.

Enumeration of Sharepoint list forms can be done via SPList.Forms. Using this you can find out which forms are registered for the list, which type they have (edit, new, display) and which one is the default form is several of one type exist.   

Since SPList.Forms is a read only collection you have to use another way of changing the forms. When a list is created, each form is provisioned as a web part page in the list itself. These pages are either stored in the hidden Forms folder of document libraries or in the RootFolder of standard lists and can be accessed as normal SPFile objects.
(http://msdn.microsoft.com/en-us/library/aa544154.aspx)

Each of these web part pages contains a WebPartManager with one ListFormWebPartUsing the TemplateName property you can specify a custom rendering template and thus create a completely individual form body while maintaining all the forms standard setup, such as buttons and toolbar.

To customize the form content whilst retaining the default setup of form page you can specify a custom rendering template for the ListFormWebPart. The rendering template is an ASCX file in TEMPLATES\CONTROLTEMPLATES and contains a <sharepoint:renderingtemplate id="[Your template name]"> tag. 

If you can assign a content type to the list you have a much easier life because you can use the NewFormTemplateName and EditFormTemplateName of the content type object. However its not always possible to assign content types, e.g. for external lists. Especially for these I find it very useful to be able to deploy a custom form.