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
SPWeb web = SPContext.Current.Web;

            SPList list = web.Lists.TryGetList(DropDownListSelectCategory.SelectedItem.Value);

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

            query.RowLimit = 10;
            query.IncludeAttachmentUrls = true;

            SPListItemCollection items = list.GetItems(query);

            Repeater1.DataSource = items;

I am using this query to take all columns from a list and display in a Repeater, but i want it also to include a attachment because it dont include in , i want it to include a hyperlink attachment.

share|improve this question

see this function for getting attachments..

public void GetListAttachments(string site, string listName)
//StringBuilder sAttNames = new StringBuilder();
using (SPSite oSite = new SPSite(site))
    using (SPWeb oWeb = oSite.OpenWeb())
        SPList oList = oWeb.Lists[listName];

        SPListItemCollection oListItems = oList.Items;
        foreach (SPListItem item in oListItems)
            SPAttachmentCollection collAttachments = item.Attachments;

            if (collAttachments.Count <= 0) return string.Empty;

            foreach (var attachment in collAttachments)
                //your attachment here
//return sAttNames.ToString();

Hope it helps...

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.