Archive for April, 2010

04/30/10
Fahad Zia
tags:  

SharePoint SPField.InternalName length


After adding the content type to SPList I get/set the item fields values using the following code:

itemNew["fieldname"]= "abc" 

which has worked fine until today when the fieldname became too long so i had this:

itemNew["ProductionInventoryControlApprovalDate"] // throws error 

after i truncate it to 32 characters like this:

itemNew["ProductionInventoryControlApprov"]  

it worked fine. This can be confirmed if you go to the list and hover on the listname it will read “ProductionInventoryControlApprov” and not “ProductionInventoryControlApprovalDate”

But this makes it hard to read so a workaround i used was get this field as site column instead:

itemNew[web.Fields.GetFieldByInternalName("ProductionInventoryControlApprovalDate").Id]

this way I can keep the code cleaner to read and debug but only if I am using code behind. If you are using custom aspx forms and using SharePoint controls for example , there is a FieldName attribute which will only take 32 characters.