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

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

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


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

            SPListItemCollection items = list.GetItems(query);

            Repeater1.DataSource = items;
            Repeater1.DataBind();

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
add comment

1 Answer

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
                //sAttNames.Append(attachment.ToString());
            }
        }
    }
}
//return sAttNames.ToString();
}

Hope it helps...

share|improve this answer
add comment

Your Answer

 
discard

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.