0

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

<%# (new SPAttachmentCollection(((SPListItem)Container.DataItem)["Attachments"].ToString()).UrlPrefix) %>

1 Answer 1

0

Morski,

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#?

4
  • 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
    Commented Jan 23, 2013 at 13:18
  • @MorskiMartin I have updated the answer! Commented Jan 23, 2013 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
    Commented Jan 23, 2013 at 13:30
  • Do it on Item databound event, instead of page file... Commented Jan 23, 2013 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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