Search code examples
sharepointsharepoint-2007splist

Adding SPFieldType.File to a custom list


When I try to add a File type field to a custom list I get

System.InvalidOperationException: Operation is not valid due to the current state of the object

Guid listGuid = adminWeb.Lists.Add(queueListName, "DotNetNuke Document Queue", SPListTemplateType.GenericList);

queueList = adminWeb.Lists[listGuid];
queueList.Fields.Add("Status", SPFieldType.File, false);

queueList.Update();

Solution

  • I don't believe that you can have a "File" field. If you look in the UI, there is no "File" field type for custom/generic list.

    If you need 1 file per item and it is mandatory, then you should be using a document library.

    If you need more than 1 file per list item, then file attachments is the way to go.