Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Share .NET
>
Tutorial
> Search paging
The following example shows you how to implement paging for search results.
C# example
using System; using System.Net; using Independentsoft.Share; namespace Sample { class Program { static void Main(string[] args) { try { Service service = new Service("https://independentsoft.sharepoint.com", "username", "password"); Independentsoft.Share.Kql.Contains restriction1 = new Independentsoft.Share.Kql.Contains(SearchResultPropertyName.Path, "https://independentsoft.sharepoint.com/Shared Documents/"); SearchQuery query = new SearchQuery(restriction1); query.SelectProperties.Add(SearchResultPropertyName.Title); query.SelectProperties.Add(SearchResultPropertyName.Path); query.RowLimit = 100; while (true) { SearchResult searchResult = service.Search(query); SimpleDataTable table = searchResult.PrimaryQueryResult.RelevantResult.Table; foreach (SimpleDataRow row in table.Rows) { foreach (KeyValue cell in row.Cells) { if (cell.Key == SearchResultPropertyName.Title) { Console.WriteLine("Title: " + cell.Value); } else if (cell.Key == SearchResultPropertyName.Path) { Console.WriteLine("Path: " + cell.Value); } } } query.StartRow += table.Rows.Count; if (query.StartRow >= searchResult.PrimaryQueryResult.RelevantResult.TotalRows) { break; } } Console.Read(); } catch (ServiceException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.ErrorCode); Console.WriteLine("Error: " + ex.ErrorString); Console.WriteLine("Error: " + ex.RequestUrl); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Share Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Try Dim service As New Service("https://independentsoft.sharepoint.com", "username", "password") Dim restriction1 As New Independentsoft.Share.Kql.Contains(SearchResultPropertyName.Path, "https://independentsoft.sharepoint.com/Shared Documents/") Dim query As New SearchQuery(restriction1) query.SelectProperties.Add(SearchResultPropertyName.Title) query.SelectProperties.Add(SearchResultPropertyName.Path) query.RowLimit = 100 While (True) Dim searchResult As SearchResult = service.Search(query) Dim table As SimpleDataTable = searchResult.PrimaryQueryResult.RelevantResult.Table For Each row As SimpleDataRow In table.Rows For Each cell As KeyValue In row.Cells If cell.Key = SearchResultPropertyName.Title Then Console.WriteLine("Title: " + cell.Value) ElseIf cell.Key = SearchResultPropertyName.Path Then Console.WriteLine("Path: " + cell.Value) End If Next Next query.StartRow += table.Rows.Count If query.StartRow >= searchResult.PrimaryQueryResult.RelevantResult.TotalRows Then Exit While End If End While Console.Read() Catch ex As ServiceException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.ErrorCode) Console.WriteLine("Error: " + ex.ErrorString) Console.WriteLine("Error: " + ex.RequestUrl) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*