我有一个 SharePoint 网站,我正在使用 Silverlight 客户端对象模型放置 Silverlight 前端。我需要为其提取数据的列表之一有附件。我需要找到一种方法来列出这些附件,但我似乎找不到这样做的方法。
ListItem 上有一个“附件”字段,但它只是一个 bool 值,表明附件是否存在。
我已经看到很多使用 SPListItem 的例子,但是我该如何使用 Silverlight 客户端对象模型来实现呢?
最佳答案
在 ScottyG30 的回答和 this thread 上的回答的帮助下,我也遇到了这个问题。我写了一个从 ListItem 中检索附件的函数:
// this method needs to be executed in background thread
public String[] GetAttachments(ClientContext ctx, List list, ListItem item)
{
// these properties can be loaded in advance, outside of this method
ctx.Load(list, l => l.RootFolder.ServerRelativeUrl);
ctx.Load(ctx.Site, s=>s.Url);
ctx.ExecuteQuery();
// get the item's attachments folder
Folder attFolder = ctx.Web.GetFolderByServerRelativeUrl( list.RootFolder.ServerRelativeUrl + "/Attachments/" + item.Id);
FileCollection files = attFolder.Files;
// I needed only urls, so I am loading just them
ctx.Load(files, fs => fs.Include(f => f.ServerRelativeUrl));
ctx.ExecuteQuery();
// now you have collection of files
return (from file in files select ctx.Site.Url + file.ServerRelativeUrl).ToArray();
}
虽然这对我有用,但当您需要大列表中所有项目的附件(url)时(每个项目都在执行查询
),在我看来这并不是最佳解决方案。
关于c# - 如何通过 Silverlight 客户端对象模型从 SharePoint 检索列表项的附件,或至少检索附件的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6525476/