0

有谁知道如何使用 SharePoint 中的客户端 .Net 对象模型读取 ListItem 的附件数量和名称等?

谢谢

4

1 回答 1

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

于 2011-11-30T22:12:43.190 回答