本文整理汇总了C#中ClientContext.LoadQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ClientContext.LoadQuery方法的具体用法?C# ClientContext.LoadQuery怎么用?C# ClientContext.LoadQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ClientContext
的用法示例。
在下文中一共展示了ClientContext.LoadQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypedFields
protected override IEnumerable<Field> GetTypedFields(ClientContext context, FieldCollection items)
{
var typedFields = context.LoadQuery(items.Where(i => i.TypeAsString == BuiltInFieldTypes.TaxonomyFieldType));
context.ExecuteQueryWithTrace();
var result = new List<Field>();
result.AddRange(typedFields);
typedFields = context.LoadQuery(items.Where(i => i.TypeAsString == BuiltInFieldTypes.TaxonomyFieldTypeMulti));
context.ExecuteQueryWithTrace();
result.AddRange(typedFields);
return result;
}
示例2: GetTypedFields
protected override IEnumerable<Field> GetTypedFields(ClientContext context, FieldCollection items)
{
var typedFields = context.LoadQuery(items.Where(i => i.TypeAsString == BuiltInPublishingFieldTypes.HTML));
context.ExecuteQueryWithTrace();
return typedFields;
}
示例3: GetTypedFields
protected override IEnumerable<Field> GetTypedFields(ClientContext context, FieldCollection items)
{
var typedFields = context.LoadQuery(items.Where(i => i.FieldTypeKind == FieldType.User));
context.ExecuteQueryWithTrace();
return typedFields;
}
示例4: GetTypedFields
protected override IEnumerable<Field> GetTypedFields(ClientContext context, FieldCollection items)
{
var typedFields = context.LoadQuery(
items.Where(i => i.FieldTypeKind == FieldType.Number)
.IncludeWithDefaultProperties());
context.ExecuteQueryWithTrace();
return typedFields;
}
示例5: GetWebLists
public static IEnumerable<List> GetWebLists(ClientContext context)
{
var retVal =
context.LoadQuery(
context.Web.Lists.Include(l => l.Id, l => l.RootFolder, l => l.RootFolder.Name,
l => l.RootFolder.ContentTypeOrder, l => l.Fields, l => l.ContentTypes));
context.ExecuteQuery();
return retVal;
}
示例6: GetWebList
public static List GetWebList(ClientContext context, string listName)
{
var listCollection =
context.LoadQuery(
context.Web.Lists.Where(l => l.RootFolder.Name == listName)
.Include(l => l.Id, l => l.RootFolder, l => l.RootFolder.Name,
l => l.RootFolder.ContentTypeOrder, l => l.Fields, l => l.ContentTypes));
context.ExecuteQuery();
return listCollection.FirstOrDefault();
}
示例7: VerifyDocLib
// This function will be triggered based on the schedule you have set for this WebJob
public static void VerifyDocLib()
{
var url = ConfigurationManager.AppSettings["SpUrl"].ToString();
var user = ConfigurationManager.AppSettings["SpUserName"].ToString();
var pw = ConfigurationManager.AppSettings["SpPassword"].ToString();
using (PnPMonitoredScope p = new PnPMonitoredScope())
{
p.LogInfo("Gathering connect info from web.config");
p.LogInfo("SharePoint url is " + url);
p.LogInfo("SharePoint user is " + user);
try
{
ClientContext cc = new ClientContext(url);
cc.AuthenticationMode = ClientAuthenticationMode.Default;
cc.Credentials = new SharePointOnlineCredentials(user, GetPassword(pw));
using (cc)
{
if (cc != null)
{
string listName = "Site Pages";
p.LogInfo("This is what a Monitored Scope log entry looks like in PNP, more to come as we try to validate a lists existence.");
p.LogInfo("Connect to Sharepoint");
ListCollection lists = cc.Web.Lists;
IEnumerable<List> results = cc.LoadQuery<List>(lists.Where(lst => lst.Title == listName));
p.LogInfo("Executing query to find the Site Pages library");
cc.ExecuteQuery();
p.LogInfo("Query Executed successfully.");
List list = results.FirstOrDefault();
if (list == null)
{
p.LogError("Site Pages library not found.");
}
else
{
p.LogInfo("Site Pages library found.");
ListItemCollection items = list.GetItems(new CamlQuery());
cc.Load(items, itms => itms.Include(item => item.DisplayName));
cc.ExecuteQueryRetry();
string pgs = "These pages were found, " + string.Join(", ", items.Select(x => x.DisplayName));
p.LogInfo(pgs);
}
}
}
}
catch (System.Exception ex)
{
p.LogInfo("We had a problem: " + ex.Message);
}
}
}
示例8: GetSiteLists
private static IEnumerable<List> GetSiteLists(string siteUrl)
{
// TODO possible context should be have the one instance for each site
using (var context = new ClientContext(siteUrl))
{
var query = from lists in context.Web.Lists
where !lists.Hidden
select lists;
var siteLists = context.LoadQuery(query);
context.ExecuteQuery();
return siteLists;
}
}
示例9: GetRoleAssignmentByPrincipal
public static SPDGRoleAssignment GetRoleAssignmentByPrincipal(SecurableObject securableObject, ClientContext context, SPDGPrincipal principal)
{
var principalId = principal.ID;
var roleAss = securableObject.RoleAssignments.Where(x => x.PrincipalId == principalId).Include(x => x.RoleDefinitionBindings, x => x.Member, x => x.PrincipalId);
var results = context.LoadQuery(roleAss);
context.ExecuteQuery();
if (results.Any())
{
return new SPDGClientRoleAssignment(results.First(), principal, results.First().RoleDefinitionBindings.Select(x => new SPDGClientRoleDefinition(x)));
}
else
{
return null;
}
}
示例10: GetListByTitle
/// <summary>
/// Check list exsited or not in site
/// </summary>
/// <param name="clientContext"></param>
/// <param name="listTitle"></param>
/// <returns>List</returns>
private static List GetListByTitle(ClientContext clientContext, String listTitle)
{
List existingList;
Web web = clientContext.Web;
ListCollection lists = web.Lists;
IEnumerable<List> existingLists = clientContext.LoadQuery(
lists.Where(
list => list.Title == listTitle)
);
clientContext.ExecuteQuery();
existingList = existingLists.FirstOrDefault();
return existingList;
}
示例11: MainWindow
public MainWindow()
{
InitializeComponent();
ClientContext context = new ClientContext("http://intranet.contoso.com");
Web site = context.Web;
context.Load(site, osite => osite.Title);
context.ExecuteQuery();
Title = site.Title;
ListCollection lists = site.Lists;
IEnumerable<SP.List> listsCollection =
context.LoadQuery(lists.Include(l => l.Title, l => l.Id));
context.ExecuteQuery();
ListBox1.ItemsSource = listsCollection;
ListBox1.DisplayMemberPath = "Title";
}
示例12: CheckFeatureActivation
public static bool CheckFeatureActivation(ClientContext context, Guid featureId, FeatureScope scope)
{
FeatureCollection features = null;
switch (scope)
{
case FeatureScope.Web:
features = context.Web.Features;
break;
case FeatureScope.Site:
features = context.Site.Features;
break;
default:
throw new NotImplementedException();
}
var featureCollection = context.LoadQuery(features.Include(f => f.DefinitionId));
context.ExecuteQuery();
return featureCollection.Any(f => f.DefinitionId.Equals(featureId));
}
示例13: GetLibraries
public static List<SPLibrary> GetLibraries(string webUrl)
{
var context = new ClientContext(webUrl);
var web = context.Web;
context.Load(web, w => w.Title, w => w.Description);
var query = from list in web.Lists.Include(l => l.Title, l => l.Id)
where list.Hidden == false && list.BaseType == BaseType.DocumentLibrary
select list;
var lists = context.LoadQuery(query);
context.ExecuteQuery();
var libraries = new List<SPLibrary>();
foreach (var list in lists)
libraries.Add(new SPLibrary()
{
Title = list.Title,
Id = list.Id,
WebUrl = webUrl
});
return libraries;
}
示例14: GetContentType
/// <summary>
/// Returns content type associated with the list.
/// </summary>
/// <param name="list">List object</param>
/// <param name="clientContext">Client Context object</param>
/// <returns>Content type object</returns>
internal static ContentType GetContentType(List list, ClientContext clientContext)
{
ContentType targetDocumentSetContentType = null;
ContentTypeCollection listContentTypes = null;
try
{
listContentTypes = list.ContentTypes;
clientContext.Load(
listContentTypes,
types => types.Include(
type => type.Id,
type => type.Name,
type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == ConstantStrings.OneDriveDocumentContentType));
clientContext.ExecuteQuery();
targetDocumentSetContentType = result.FirstOrDefault();
}
catch (Exception exception)
{
Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
}
return targetDocumentSetContentType;
}
示例15: DoWork
private static void DoWork()
{
Console.WriteLine();
Console.WriteLine("Url: " + url);
Console.WriteLine("User Name: " + userName);
Console.WriteLine("List Name: " + listName);
Console.WriteLine();
try
{
Console.WriteLine(string.Format("Connecting to {0}", url));
Console.WriteLine();
ClientContext cc = new ClientContext(url);
cc.AuthenticationMode = ClientAuthenticationMode.Default;
cc.Credentials = new SharePointOnlineCredentials(userName, password);
ListCollection lists = cc.Web.Lists;
IEnumerable<List> results = cc.LoadQuery<List>(lists.Where(lst => lst.Title == listName));
cc.ExecuteQuery();
List list = results.FirstOrDefault();
if (list == null)
{
Console.WriteLine("A list named \"{0}\" does not exist. Press any key to exit...", listName);
Console.ReadKey();
return;
}
nextRunTime = DateTime.Now;
ChangeQuery cq = new ChangeQuery(false, false);
cq.Item = true;
cq.DeleteObject = true;
cq.Add = true;
cq.Update = true;
// Initially set the ChangeTokenStart to 2 days ago so we don't go off and grab every item from the list since the day it was created.
// The format of the string is semicolon delimited with the following pieces of information in order
// Version number
// A number indicating the change scope: 0 – Content Database, 1 – site collection, 2 – site, 3 – list.
// GUID representing the scope ID of the change token
// Time (in UTC) when the change occurred
// Number of the change relative to other changes
cq.ChangeTokenStart = new ChangeToken();
cq.ChangeTokenStart.StringValue = string.Format("1;3;{0};{1};-1", list.Id.ToString(), DateTime.Now.AddDays(-2).ToUniversalTime().Ticks.ToString());
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("Ctrl+c to terminate. Press \"r\" key to force run without waiting {0} seconds.", WaitSeconds));
Console.WriteLine();
Console.ResetColor();
do
{
do
{
if (Console.KeyAvailable && Console.ReadKey(true).KeyChar == 'r') { break; }
}
while (nextRunTime > DateTime.Now);
Console.WriteLine(string.Format("Looking for items modified after {0} UTC", GetDateStringFromChangeToken(cq.ChangeTokenStart)));
ChangeCollection coll = list.GetChanges(cq);
cc.Load(coll);
cc.ExecuteQuery();
DisplayChanges(coll, cq.ChangeTokenStart);
// if we find any changes to the list take the last change and use the ChangeToken as the start time for our next query.
// The ChangeToken will contain the Date/time of the last change to any item in the list.
cq.ChangeTokenStart = coll.Count > 0 ? coll.Last().ChangeToken : cq.ChangeTokenStart;
nextRunTime = DateTime.Now.AddSeconds(WaitSeconds);
} while (true);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}