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

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

1 Answer 1


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? –  Martin 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); } ' –  Martin 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.