I created a custom list and the user can attach two files that is stored in listitem.attachments.
I try to give the user a delete button but when I perform the delete I get an error.
When I press the delete (image button) the page postback and if I click for example another button (a save button or an add attachment button) it raises an SP Exception (No item exists at
http://server/site/Pages/edit.aspx?id=37. It may have been deleted or renamed by another user). If I go to the list and then return in the item everything is fine.
In order to add the attachment I am using the following code:
if (FileUpload.PostedFile != null && FileUpload.HasFile)
Stream fStream = AnswerFileUpload.PostedFile.InputStream;
byte contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
SPAttachmentCollection attachments = myItem.Attachments;
string FileName = Path.GetFileName(AnswerFileUpload.PostedFile.FileName);
View Complete Post