This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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