1

When I'm saving attachment to list item, an exception is thrown: The list item was saved, but one or more attachments could not be saved.
Could not upload file xyz.txt.

Despite the exception, list item is properly saved and attachment is correctly added.

The code for saving attachment is executed in method "UpdateFieldValueInItem" in control for my custom field.

1 Answer 1

2

Does your custom field control has any asp:FileUpload control? I had similar issue with with my custom field under this condition. And reason for that was because Microsoft.SharePoint.WebControls.AttachmentField, which I think is by default on every New/Edit item forms, internally iterates through this.Context.Request.Files and tries to create attachment for each file. I think everything works fine, cause this field is processed as last one. And for me, solution was to include following code in UploadFieldValueInItem after processing custom FileUpload control:

if (FileUpload.HasFile)
{
     var member = Context.Request.Files.GetType().GetMethod("BaseRemove",
                  BindingFlags.Instance | BindingFlags.NonPublic);
     member.Invoke(Context.Request.Files, new[] { FileUpload.UniqueID });
}
1
  • My control was uploading attachments (by using input html tags). You're right - AttachmentsField iterates over Request.Files and adds files as attachmets. Your solution (by removing given file from Request.Files) worked. Commented Oct 19, 2012 at 12:08

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.