0

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)
    {
        try
        {
            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;
                RepeaterContent.DataBind();
            }
        }
        catch (Exception)
        {
            LabelException.Text = LabelException.Text =  "";
        }
    }

Any suggestions?

1 Answer 1

0

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.

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.