0
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.

0

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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