- I have a sharepoint site.
- It has around hundred document libraries.
- i want to get the name and link of today uploaded documents in the sharepoint site using client object model.
- pls help
To search documents in SharePoint you can use search API of 2013 share point follow these below steps to find out solution
- Search service application created and running with good crawl system scheduled.
-
Enable continuous crawl, so that new results will appear.
-
Make sure your document library is set to YES to Allow items to appear in search results in the Advanced Settings of the doc library
- Also additionally you can set up a search scope for the document library and use KeywordQuery to search in that scope(You can set the scope at site collection).This step is not a required step since you can put the URL of the document library inside the Query to get only docs from that library
Code is here
using (ClientContext clientContext = new ClientContext("http://<serverName>/sites/<siteCollectionPath>")) { KeywordQuery keywordQuery = new KeywordQuery(clientContext); keywordQuery.QueryText = "SharePoint";//change this to suit your need SearchExecutor searchExecutor = new SearchExecutor(clientContext); ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery); clientContext.ExecuteQuery(); }
- Edited by Ankit Pareek 9 minutes ago
To search documents in SharePoint you can use search API of 2013 share point follow these below steps to find out solution
- Search service application created and running with good crawl system scheduled.
-
Enable continuous crawl, so that new results will appear.
-
Make sure your document library is set to YES to Allow items to appear in search results in the Advanced Settings of the doc library
- Also additionally you can set up a search scope for the document library and use KeywordQuery to search in that scope(You can set the scope at site collection).This step is not a required step since you can put the URL of the document library inside the Query to get only docs from that library
Code is here
using (ClientContext clientContext = new ClientContext("http://<serverName>/sites/<siteCollectionPath>")) { KeywordQuery keywordQuery = new KeywordQuery(clientContext); keywordQuery.QueryText = "SharePoint";//change this to suit your need SearchExecutor searchExecutor = new SearchExecutor(clientContext); ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery); clientContext.ExecuteQuery(); }
- Edited by Ankit Pareek 16 minutes ago
This can be achieved by SharePoint search query,
code for Javascript to get search result - this you will need to call on search button click
var context = SP.ClientContext.get_current(); var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context); keywordQuery.set_queryText("Search Query"); var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context); var results = searchExecutor.executeQuery(keywordQuery); context.executeQueryAsync(onQuerySuccess, onQueryFail); function onQuerySuccess() { $("#resultsDiv").append('<table>'); if (results.m_value.ResultTables) { $.each(results.m_value.ResultTables, function(index, table) { if(table.TableType == "RelevantResults") { $.each(results.m_value.ResultTables[index].ResultRows, function () { $("#resultsDiv").append('<tr>'); $("#resultsDiv").append('<td>' + this.Title + '</td>'); $("#resultsDiv").append('<td>' + this.Author + '</td>'); $("#resultsDiv").append('</tr>'); }) } }); } $("#resultsDiv").append('</table>'); } function onQueryFail(){ alert('Query failed. Error:' + args.get_message()); }
Now you will need to create your 'Query Text'. Few examples of that:
1) As you need only documents then it will contain 'isDocument:true'
2) If there is specific Parent Content type of all the documents then you can add filter : 'ContentTypeId:{your parent content type id}*'
3) For today's date document -> You will need to add one filter something like 'Created:{Today}'. You can create a Managed Property of Created if not present, and then use normal javascript to get Today's date to form the query.
Here is link for creating 'Created Date' managed property https://social.technet.microsoft.com/forums/sharepoint/en-US/2ddab5dd-1f21-485e-b193-ededc80b46bc/create-date-managed-property-for-search-web-service
So, overall query will look as follows :
"isDocument:true AND Created:24/06/2015 AND ContentTypeId:{Parent Content Type (if any)}"