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

new SPAttachmentCollection is getting red what the problem? Want to display an attachment in Repeater

<%# (new SPAttachmentCollection(((SPListItem)Container.DataItem)["Attachments"].ToString()).UrlPrefix) %>
share|improve this question


Instead can you try the following:

<%# (((SPListItem)Container.DataItem).Attachments.UrlPrefix) %>

UrlPrefix property will give you only the Url Prefix part for the Attachments, you need to append the attachment file name to make complete Attachment Url...

Please follow below link:
How do I get the url for attachments on an SPListItem using C#?

share|improve this answer
Hi! Thanks for the help! but i get this following error on my site wingtip:49074/Lists/News-ListInstance1/Attachments/1 and not the attachment? – Batistuta Jan 23 '13 at 13:18
@MorskiMartin I have updated the answer! – Arsalan Adam Khatri Jan 23 '13 at 13:22
Hi i have tryed with this code,but dont get it to work 'private IEnumerable<string> GetAttachmentUrls(SPListItem item) { return from string fileName in item.Attachments orderby fileName select SPUrlUtility.CombineUrl(item.Attachments.UrlPrefix, fileName); } ' – Batistuta Jan 23 '13 at 13:30
Do it on Item databound event, instead of page file... – Arsalan Adam Khatri Jan 23 '13 at 14:24

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.