Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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 });
}
share|improve this answer
    
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. –  user1252773 Oct 19 '12 at 12:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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