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

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... –  Martin 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.... –  Martin Dec 6 '12 at 9:49
    
i.stack.imgur.com/VnYCm.png like this but i am insted using an listbox and button instead for an fileupload –  Martin Dec 6 '12 at 9:53

1 Answer 1

            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 
            myLibrary.Update();

I think it's good enought

share|improve this answer

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.