I tried using this solution with the following code:

 using (SPWeb web = site.OpenWeb())
        SPList list = web.Lists[ListName];
        items = list.GetItems();
        table = items.GetDataTable();

        DataColumn urlAttachs = table.Columns.Add("AttachUrl", typeof(String));
        string t;
        foreach (DataRow row in table.Rows)
          foreach (SPListItem listItem in list.Items)
             t = GetAttachmentUrls(listItem).ToString();
             row["AttachUrl"] = t;

But as a result I got only one attachment, which was added last. How can I get the full list of attachments for every item in the list? What am I doing wrong?


Once you intance the item, loop within attachments collection.

Sample code:

SPAttachmentCollection attachments = listItem.Attachments;
foreach (string attachment in attachments)
  string t = SPUrlUtility.CombineUrl(listItem.Attachments.UrlPrefix, attachment );

Source: SurPoint

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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