如何使用客户端对象模型sharepoint 2010从文档库中搜索文件

时间:2012-07-05 14:51:41

标签: sharepoint-2010 client-object-model sharepoint-clientobject

目前我正在努力以编程方式启用搜索功能,使用客户端对象模型sharepoint 2010从文档库中搜索文件,

你能帮我解决一下代码吗

由于

Kajal

2 个答案:

答案 0 :(得分:1)

List list = clientcontext.Web.Lists.GetByTitle(ListName);
clientcontext.Load(list);
clientcontext.ExecuteQuery();

FileCollection files = list.RootFolder.Files;
clientcontext.Load(files);
clientcontext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.File file in files)
{
    if(file.Name == txtSearch)
    {
        // your logic
    }

}

答案 1 :(得分:0)

 private string searchDoc(string name)
    {
        try
        {
            ClientContext clientContext = new ClientContext("YOUR SERVER");
            SP.List oList = clientContext.Web.Lists.GetByTitle("YOUR DOC");
            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = @"<View Scope='Recursive'/>";
            Microsoft.SharePoint.Client.ListItemCollection collListItem1 = oList.GetItems(camlQuery);
            clientContext.Load(collListItem1, items => items.Include(item => item.DisplayName, item => item["Comments"]));
            clientContext.ExecuteQuery();
            foreach (Microsoft.SharePoint.Client.ListItem oListItem1 in collListItem1)
            {
                 if (oListItem1.DisplayName == name)
                 {
                     XXXXXXXXXXXXXX
                 }
            }

        catch (Exception ex)
        {
            System.Windows.MessageBox.Show(ex.Message, "Exception");
        }
    }

递归搜索!