0
votes

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?

1
Maybe ID is required?trigras
I had added all fields include 'ID' and 'Created' to ViewFields but no luck, that error still there.cpyd

1 Answers

2
votes

I encountered same error but I guessed it was due to udpate requires few more fields.
I found the blog and agree with that.

So leaving ViewFieldsOnly to default (false) is the only choice in case of updation.