Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Microsoft.SharePoint.Client;
using System;
using System.Text;
using System.Web;
namespace BlogNoneSpFullPageWeb
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var search = HttpUtility.ParseQueryString(Request.Url.Query).Get("search");
var hostUrl = HttpUtility.ParseQueryString(Request.Url.Query).Get("SPHostUrl");
Uri spHostUrl = new Uri(hostUrl);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(spHostUrl, Request.LogonUserIdentity))
{
List spList = clientContext.Web.Lists.GetByTitle("Custom List");
StringBuilder buildQuery = new StringBuilder();
buildQuery.Append("<View><Query><Where><Contains>");
buildQuery.Append("<FieldRef Name='Title' /><Value Type='Text'>");
buildQuery.Append(search);
buildQuery.Append("</Value></Contains></Where></Query></View>");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =buildQuery.ToString();
ListItemCollection listItems = spList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (var item in listItems)
{
Result.Text += item["Title"].ToString() + "<br/>";
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.