Updating SharePoint field links
Asked Answered
B

1

6

I used a piece of code that retrieves a field link for a specified content type and sets the field to either required or not required. This works fine but when I try to do the same for a field that has spaces in the name, the code throws an error.

SPField col = //some column retrieved from a list
SPContentType ct = col.ParentList.ContentTypes["MyContentTypeName"] //gets the content type

SPFieldLink fieldLink = ct.FieldLinks["MyFieldname"]; // gets the fieldLink
ct.Update(); 

It works if MyFieldName is a string like "Hobbies" or "Amount", but fails if it's a string like "Full Name".

Is there a workaround?

Blesbok answered 4/12, 2012 at 15:29 Comment(2)
Please include the error message.Poesy
For anyone relying on the code shown in the question, note that SPFieldLink does not have an Update method as suggested. The code should show ct.Update, not fieldLink.Update.Jarita
L
4

You are probably using the field display name instead of the field internal name

Have you tried: "Full_x0020_Name" ?

Leilanileininger answered 18/12, 2012 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.