4

I am creating a SharePoint list with C# and have created a "Hyperlink or Picture" field like so:

myList.Fields.add("Icon", SPFieldType.URL, true);

when I add an item to the list in SharePoint this field is displayed as a hyperlink. By editing the list settings in SharePoint, I can change the "Format URL as" option from "Hyperlink" to "Picture" and it works as desired.

enter image description here

How can I set the field to display as picture when creating the field programmatically?

1
  • 2
    Sorry, I don't have the time to give you detailed code, but you have to set this property msdn.microsoft.com/en-us/library/…. So cast the field to SPFieldUrl and then set the property DisplayFormat and call Update() Commented Nov 4, 2014 at 15:54

1 Answer 1

4

You need to use 'DisplayFormat`

SPFieldUrl fldURLImage = (SPFieldUrl)list.Fields.CreateNewField(SPFieldType.URL.ToString(), "Picture");
fldURLImage.DisplayFormat = SPUrlFieldFormatType.Image;
myList.Fields.Add(fldURLImage,SPFieldType.URL, true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.