Friday 16 July 2010

All about SPField - Internal Name, Display Name, & GUID

First of all, Thank goes to Ken for the investigation.

Few words on the web about internal, static and display names of columns. There aren’t any simple Microsoft statement on the subject


Create Site Column through GUI:

-- DisplayName must be unique. SharePoint will adjust StaticName & InternalName to keep them unique.

Create Site Column through Feature and XML:

-- xml-Name (InternalName) must be unique. SharePoint will allow duplicate DisplayName & StaticName.
*** Duplicate Internal names will not create a field (If you already have a site field with the same Internal Name). “No error will be raised”.

Create List Column through GUI:

-- DisplayName must be unique. SharePoint will adjust StaticName & InternalName to keep them unique.

Adding site columns to list columns via GUI:

-- DisplayName and StaticName don't have to be unique. SharePoint will make InternalName unique.


Source: http://www.sharepointlessonslearned.com/blogs/blog1.php/2010/03/04/field-name-uniqueness-rules-vary-between-gui-and-api


In addition to that:

** Content types that refer to the missing field will have orphaned local field, and the list will continue to function.

** Fields created from code (Fields.AddFieldAsXml) - These will raise an error if internal name exists.

** Fields created from code (Fields.Add) - Sharepoint makes unique name.

Wednesday 3 February 2010

Adding event receivers to custom list templates

Problem: wanted to create a list template and with some event receivers.

Normally I use the SharePoint Solution Generator to dump the list templates. So I have created a list using GUI and added some event receivers and used the SSG to generate the template. (I got my 4 aspx files and the schema.xml)




When you check the schema, you can see that the Event receivers are correctly added under the <Receivers> tag. So I have used a feature to deploy the list template and created a list using deployed template. List was created successfully with all the fields and views, but unfortunately my Event receivers were missing. I doubled checked and tried again, got the same results.

While googleing, found an article which you can use a separate Elements file to bind the Event receivers to particular list type.

I have use the same method and its working with the list template. In addition to that it adds the event receivers to list which are already created through my custom template.

Note that you need to correctly match the ListTemplateOwner and ListTemplateId





So, basically this registers the event receivers based on the list type and you can use this to add event receivers to existing custom list by just creating a feature, rather than writing new codes.