DEV Community 👩‍💻👨‍💻

Cover image for Using KeywordQuery with CSOM SharePoint Online
Ricardo Costa
Ricardo Costa

Posted on • Originally published at blogit.create.pt on

Using KeywordQuery with CSOM SharePoint Online

string username = "***********";
string pwd = "*********";
string siteURL = "**********";

ClientContext context = new ClientContext(siteURL);
Web web = context.Web;
SecureString pass = new SecureString();
foreach (char c in pwd.ToCharArray()) pass.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials(username, passWord);
try
{
    KeywordQuery query = new KeywordQuery(context);
    query.QueryText = "ContentType:Factura AND PrecoOWSCURR>10000";

    query.RowLimit = 10;
    query.RowsPerPage = 10;
    SearchExecutor search = new SearchExecutor(context);
    ClientResult<ResultTableCollection> results = search.ExecuteQuery(query);
    context.ExecuteQuery();

    foreach (var resultRow in results.Value[0].ResultRows)
    {
        Console.WriteLine("{0}", resultRow["Title"]);
    }
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
    Console.ReadKey();
}

The post Using KeywordQuery with CSOM SharePoint Online appeared first on Blog IT.

Top comments (0)

Take Your Github Repository To The Next Level

Take Your Github Repository To The Next Level 🚀️: A step-by-step guide on creating the perfect Github repository.