SPField

Updating the title within a SPItemEventReceiver with AfterProperties

Recently I had a problem setting the title field of a Page within the pages library. My requirement was to set the title with the value from the PageTitle field of the current item. An ItemEventReceiver, which is executed synchronously to prevent save conflict exception or problems with published items, was supposed to do exactly that. But when I set the title property of the item via AfterProperties, the value did not get stored.

Custom field and UpdateFieldValueInItem()

Recently I was developing a custom field. To store modified values, the UpdateFieldValueInItem method has to be overwritten. In a normal way of clicking the submit/save button, the method is called and I can adjust the value for the field within the current item. The changes are submitted to the database later. But what if you want to modify items outside of the current item? Sure, you can do so would you think.

Creating a lookup field via elements.xml

This is another post to help me remember. And as a reference for all of you, who cannot remember how to create a SPFieldLookup via XML. <Field ID="{8b26ec41-b6c3-4327-0066-0c18c0768626}" Name="InternalName" StaticName="InternalName" DisplayName="Display Name" Type="Lookup" ShowField="Title" Mult="TRUE" List="Lists/LookupList" Overwrite="TRUE" /> When you provision a SPField via features, do not forget to add Overwrite=”TRUE”! Otherwise you’ll get an exception like this: 0x8107058aFehler beim Binden des Inhaltstyps ‘0x010200C7A18EB120BB4A00892E9E1EE9481C9B0067E475B6FDD54048B347370871443CAD’ an die Liste ‘/sites/rhtest/Lists/LookupList’ für ‘http://rhdevsp2013/sites/rhtest’. Ausnahme ‘0x80070057’.

StaticName != InternalName

Recently I was trying to fetch a SPField from a SPWeb object. I had SharePoint 2010, so I decided to use the new SPFieldCollection.TryGetFieldByStaticName() Method. You can imagine how surprised I was, that I couldn’t get the field I was looking for. What do we learn? Well, the StaticName of an SPField is not necessarily the InternalName! Here is a link to the MSDN about SPField.StaticName: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.staticname.aspx

Issues in WSS V2

Responses to items in an Issue list (SPListIssue) are new version in WSS V3. WSS V2 lacks the ability to use versions for lists. So what did Microsoft do that an Issue list behaves like it is using versions? In WSS V2 items in a single “thread” all have different ItemIDs. To group them together, all have the same IssueID. This is the ItemID from the original item. A single issue in WSS V2 could look like this:

SPQuery, ViewFields and empty fields

If you want your query to return empty columns, you have to add Nullable=’TRUE’ to the viewfields. If you do not add the Nullable attribute, accessing the results of the query like this: oListItemAvailable[“Field1”] will give an Exception. I’ve made posted a comment about this on the page in the MSDN http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx

Supported field types as source for Lookup Fields

Lookup fields are great. They can show information from other lists. I have never noticed before, that the only two supported field types for lookups are SPFieldText and SPFieldCalculated. All other field types can not be used as source for lookup fields.Technorati Tags: SharePoint,SPFieldLookup,SPFieldText,SPFieldCalculated

SharePoint Bug with MultiValue Fields

Imagine you have a list (or document library) which has lots of items. Nothing fancy here. Now add a lookup or user field and allow it to contain multiple values. Inside a view for this list you can filter e.g. for the title column. The filter dropdown shows all possible values for the column. Here comes the clue. If the item count of the list reaches a number somewhere between 400 and 500 items, the filter dropdown changes.

Programmatically creating a SPFieldCalculated

As you might already know, you can create new fields with SPFieldCollection.AddFieldAsXml(string schema). The schema contains the formula for the calculated field. There are some points to take care of, before you can add the field: make sure your referenced fieldnames are the display names and not the internal field names the formula has to be in the English format Changing the fieldnames is an easy task. If you read the schema from a field and want to create a new one with the same formula, you will get something like “=if(fieldA,1,2)”.

Adding a custom field type via code

Your custom field type can be added to a list in a browser easily. But how do you add a custom field type via code? Here is my way: add a new field with the field type from which your custom field type derived change the field type of the new field to your own custom field type In my case my custom field type derived from a SPFieldLookup. 1: // create new lookup field <pre>&lt;font size=2>&lt;span class=lnum> 2: &lt;/span>&lt;span class=kwrd>string&lt;/span> newFieldName = fields.