MOSS2010 客户端对象模型开发(四)
2012-09-05 11:48 温森特 阅读(445) 评论(1) 编辑 收藏 举报讲完了几个常用列表的操作,现在讲述一下列表的附件的获取。列表的附件存放的相对地址一般是在列表的跟目录下Attachment文件夹下面,在客户端的对象模型中,我们依然遵循这个思路进行解决办法,通过路径的方式访问文件夹,然后遍历得到附件的信息,下面是示例代码。
using (ClientContext clientContext = new ClientContext(url))
{
clientContext.Credentials = new NetworkCredential(UserName, UserPassword, Domain));
Web web = clientContext.Web;
clientContext.Load(web);
Folder attachmentsFolder = web.GetFolderByServerRelativeUrl(webUrl + "Lists/" + listUrl + "/attachments/" + listIiteId);
clientContext.Load(attachmentsFolder);
FileCollection attachments = attachmentsFolder.Files;
clientContext.Load(attachments);
List<FileInformation> attInfoList=new List<FileInformation>();
foreach (File f in attachments)
{
attInfoList.Add(File.OpenBinaryDirect(clientContext,f.ServerRelativeUrl);
}
{
clientContext.Credentials = new NetworkCredential(UserName, UserPassword, Domain));
Web web = clientContext.Web;
clientContext.Load(web);
Folder attachmentsFolder = web.GetFolderByServerRelativeUrl(webUrl + "Lists/" + listUrl + "/attachments/" + listIiteId);
clientContext.Load(attachmentsFolder);
FileCollection attachments = attachmentsFolder.Files;
clientContext.Load(attachments);
List<FileInformation> attInfoList=new List<FileInformation>();
foreach (File f in attachments)
{
attInfoList.Add(File.OpenBinaryDirect(clientContext,f.ServerRelativeUrl);
}
您的支持,我的动力!