SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to remove an Attachment from SPList , i would like to remove it from an webpart , that uses an Listbox and an Delete Button

oreach (SPListItem customer in items)
                // ett fält som är dolt som håller i idet
                HiddenField1.Value = customer["ID"].ToString();
                TextBox_Name.Text = customer["Title"].ToString();
                TextBox_ProdNum.Text = customer["ProductNumber"].ToString();
                TextBox_Color.Text = customer["Color"].ToString();
                TextBox_ListPrice.Text = customer["ListPrice"].ToString();
                TextBox_MoreInfo.Text = customer["More Info"] != null
                                            ? customer["More Info"].ToString()
                                            : string.Empty;

                ListBox1.Items.Add(new ListItem(customer.Attachments.Add(// here it ask for an leaf but i dont know what it is)));
share|improve this question
I suggest to you to have the listitemid and the title in your listitem – Salvatore Di Fazio Dec 6 '12 at 9:39
how do u mean... – Batistuta Dec 6 '12 at 9:41
have you problem to identify in which SPListItem you must delete the attachment? – Salvatore Di Fazio Dec 6 '12 at 9:47
I have created an WebPart that searches for an Product in a List that show the product in an ListBox When presseing Make Changes button i have created an Listbox and an Button there i would like to update the Attachment in that are in my list.... – Batistuta Dec 6 '12 at 9:49 like this but i am insted using an listbox and button instead for an fileupload – Batistuta Dec 6 '12 at 9:53
            SPFolder library = web.Folders[documentLibraryName];

            // Prepare to upload
            Boolean replaceExistingFiles = true;
            String fileName = System.IO.Path.GetFileName(fileToUpload);
            FileStream fileStream = File.OpenRead(fileToUpload);

            // Upload document
            SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);

            // Commit 

I think it's good enought

share|improve this answer

Your Answer


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.