I want to add attachment to some specified List items, I used the function SPlist.GetItems(SPQuery) to get target list item, since there are many columns in the List, In order to limit the columns returned, I specified the ViewFields as below and set the "ViewFieldsOnly
" property of SPQuery
to "true".
query.ViewFields = "<FieldRef Name='Attachments' />";
I got the list item correctly and the "Attachments" property of returned SPListItem object is not null. However, after I used SPListItem.Attachments.Add()
and trying to invoke SPListItem.Update()
, an error
"value does not fall within the expected range" occur.
After looking into this issue, I found that if the "ViewFieldsOnly
" property of SPQuery
is set to "false
", that error won't occur and the attachment will be uploaded successfully. But this will return all columns of the List item and makes my program run slower.
So my question is, is there a "mandatory" column that may block attachments from being attached to List item?