简体   繁体   中英

Retrieving the url of an attachement from a sharepoint list

Guys im using the spquery object to retrieve some items from a list and populate a repeater. I need to grab the url of the attachment. Ive set IncludeAttachmentUrls to true but im not sure on the name of the field to use in the repeater.

     SPWeb Web = SPContext.Current.Web;
     SPList List = Web.Lists["LinksList"];

     SPQuery Query = new SPQuery();
     Query.Query = "<OrderBy><FieldRef Name='Title' Ascending='False' /></OrderBy>";
     Query.IncludeAttachmentUrls = true;

     RPTLinks.DataSource = List.GetItems(Query).GetDataTable();
     RPTLinks.DataBind();

I hope this might help you, it is not a fully functional/tested solution but it might give you a lead:

The foreach loop and oItem.url is what I use most after a CAML query.

     SPList List = Web.Lists["LinksList"];

     SPQuery Query = new SPQuery();
     Query.Query = "<OrderBy><FieldRef Name='Title' Ascending='False' /></OrderBy>"
ArrayList values = new ArrayList();

foreach (SPListItem oItem in oList.GetItems(Query))
{
values.Add(oItem.Url);

// You might need to add extra code here to get the full path if you need to such as spweb url etc..

}
RPTLinks.DataSource = values;

RPTLinks.DataBind();

The property is called Attachments but there is an additional operation needed to get the full url for each. Take a look at this question on SharePoint StackExchange.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM