Skip to content

Instantly share code, notes, and snippets.

@Vintaurus
Created December 27, 2017 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vintaurus/f68f0074177e2f072011ae93e49d9bb6 to your computer and use it in GitHub Desktop.
Save Vintaurus/f68f0074177e2f072011ae93e49d9bb6 to your computer and use it in GitHub Desktop.
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