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

This code creates a new listitem for every attachment but i only want to create 1 listitem and add all attachments to it

SPList myEmployeeDocList = web.Lists.TryGetList("Document cv");
if (myEmployeeDocList != null)
    SPListItem employeeDocListItem = myEmployeeDocList.Items.Add();
    employeeDocListItem["Title"] = strUserName;

    if (FileUploadDocuments.PostedFile != null && FileUploadDocuments.HasFile)
         Stream fStream = FileUploadDocuments.PostedFile.InputStream;
         byte[] empDocContents = new byte[fStream.Length];
         fStream.Read(empDocContents, 0, (int) fStream.Length);
         SPAttachmentCollection empDocAttachment = employeeDocListItem.Attachments;
         string empDocFileName = Path.GetFileName(FileUploadDocuments.FileName);

         empDocAttachment.Add(empDocFileName, empDocContents);


    string empDocListUrl = web.Url + "/" + myEmployeeDocList.RootFolder.Url;
    string empDocAttachmentUrl = empDocListUrl + "/attachments/" + employeeDocListItem.ID + "/" +

//.... cut ....
share|improve this question

Well just keep calling


for all of your attachments, preferably in a loop

foreach(var attachment in AllMyAttachments)
        var fs = new FileStream(attachment.FullName , FileMode.Open,FileAccess.Read);

        byte[] theData = new byte[fs.Length];



        employeeDocListItem.Attachments.Add(attachment.Name, theData);

share|improve this answer
please be more specified i dont get it – Batistuta Apr 11 '13 at 13:34
I really can't be more specific than this. You need to create a collection containing all of the files you wnat to add as attachments, call that AllMyAttachments and then copy paste the code block above. – Robert Lindgren Apr 11 '13 at 13:37

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.