SharePoint 2010:使用客户端对象模型计算ListItem附件

时间:2011-07-13 23:29:24

标签: sharepoint sharepoint-2010 csom

有没有人知道如何使用SharePoint中的Client .Net Object模型读取ListItem的附件数量和名称等?

由于

1 个答案:

答案 0 :(得分:0)

// For getting the list item field information

public void LoadPropertyInfo()
{
    using (context = new ClientContext(siteCollectionUrl))
    {
        spWeb = context.Web;
        propertiesList = spWeb.Lists.GetByTitle(listName);
        FieldCollection fields = propertiesList.Fields;
        context.Load(fields);
        SP.CamlQuery query = new SP.CamlQuery();
        query.ViewXml = string.Format("<View><Query><Where><Eq><FieldRef Name=\"{0}\" /><Value Type=\"Text\">{1}</Value></Eq></Where></Query></View>", propertyID, PropertyIDValue);
        listItems = propertiesList.GetItems(query);
        context.Load(listItems);
        context.ExecuteQueryAsync(GetRequestSucceeded, RequestFailed);
    }
}

// Pass the item id here for getting the attachments

private void GetAttchmentCollection(string id)
{
    string RedirectHost = string.Empty;
    string Host = string.Empty;
    context = SP.ClientContext.Current;
    RedirectHost = serviceUrl + "_vti_bin/Lists.asmx";
    BasicHttpBinding binding = new BasicHttpBinding();

    if (System.Windows.Browser.HtmlPage.Document.DocumentUri.Scheme.StartsWith("https"))
    {
        binding.Security.Mode = BasicHttpSecurityMode.Transport;
    }

    binding.MaxReceivedMessageSize = int.MaxValue;
    EndpointAddress endpoint = new EndpointAddress(RedirectHost);
    ServiceReference1.ListsSoapClient oClient = new ServiceReference1.ListsSoapClient(binding, endpoint);
    oClient.GetAttachmentCollectionCompleted += new EventHandler<ServiceReference1.GetAttachmentCollectionCompletedEventArgs>(oClient_GetAttachmentCollectionCompleted);
    oClient.GetAttachmentCollectionAsync(listName, id);
}

您也可以尝试此链接。

http://helpmetocode.blogspot.com/2011/11/managed-client-object-models-in.html