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

I'm working to show my attachments in a repeater control. It works ALMOST perfectly. I just want to get the full url to my attachment. Right now i'm getting: http://knowitintranet:9797/sites/News/Lists/KnowIT.News-ListInstance1/Attachments/1/ but i want it to show http://knowitintranet:9797/sites/News/Lists/KnowIT.News-ListInstance1/Attachments/1/banana.jpg

The aspx code i'm currently using is:

<a href="<%# ((SPListItem)Container.DataItem).Attachments.UrlPrefix %> " target="_blank"><%# ((SPListItem)Container.DataItem).Attachments[0] %></a>

This is my buttonclick event code:

    protected void ButtonChoose_Click(object sender, EventArgs e)
            using (SPSite site = new SPSite("http://knowitintranet:9797/sites/News"))
                SPWeb web = SPContext.Current.Web;
                SPList list = web.Lists.TryGetList(DropDownListCategory2.SelectedItem.Value);

                SPQuery query = new SPQuery();
                query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
                query.IncludeAttachmentUrls = true;
                query.RowLimit = 3;

                SPListItemCollection items = list.GetItems(query);

                RepeaterContent.DataSource = items;
        catch (Exception)
            LabelException.Text = LabelException.Text =  "";

Any suggestions?

share|improve this question

There are can be several attachments. I think that you can use second repeater in your fist repeater to show all attachments. How to get correct URLs for the attachments you can see in this thread.

share|improve this answer

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.