尚未在asp.net中单击按钮-C#asp.net时初始化Sharepoint集合
我是Sharepoint新手,在参考url-之后,我成功地连接到Sharepoint并在控制台应用程序C#中检索详细信息。我的问题是,当我将相同的代码移动到asp.net网站时,它会给我一个集合尚未初始化的错误。这是密码尚未在asp.net中单击按钮-C#asp.net时初始化Sharepoint集合,c#,asp.net,sharepoint,office365,sharepoint-online,C#,Asp.net,Sharepoint,Office365,Sharepoint Online,我是Sharepoint新手,在参考url-之后,我成功地连接到Sharepoint并在控制台应用程序C#中检索详细信息。我的问题是,当我将相同的代码移动到asp.net网站时,它会给我一个集合尚未初始化的错误。这是密码 using (ClientContext clientContext = new ClientContext("https://.../sites/.../")) { SecureString passWord = new SecureS
using (ClientContext clientContext = new ClientContext("https://.../sites/.../"))
{
SecureString passWord = new SecureString();
foreach (char c in "abcdefghijklmnop".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("myname@mydomain.com", passWord);
List list = clientContext.Web.Lists.GetByTitle("ABC DEF");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>1200</RowLimit></View>";
ListItemCollection collListItem = list.GetItems(camlQuery);
clientContext.Load(collListItem, li => li.Include(
pi => pi.Id,
pi => pi["Title"],
pi => pi["Application"],
pi => pi["URL"],
pi => pi["AIR_x0020_ID"]
));
clientContext.ExecuteQuery();
List<string> listofapplications = new List<string>();
foreach (ListItem oListItem in collListItem)
{
{ Console.WriteLine(oListItem["Title"] + ", Application " + oListItem["Application"]); }
}
Console.ReadLine();
}
使用(ClientContext ClientContext=new ClientContext(“https://.../sites/.../"))
{
SecureString密码=新SecureString();
foreach(在“abcdefghijklmnop.ToCharArray()”中的字符c)passWord.AppendChar(c);
clientContext.Credentials=新的SharePointOnlineCredentials(“myname@mydomain.com“,密码);
List List=clientContext.Web.Lists.GetByTitle(“ABC DEF”);
CamlQuery CamlQuery=新的CamlQuery();
camlQuery.ViewXml=“1200”;
ListItemCollection collListItem=list.GetItems(camlQuery);
Load(collListItem,li=>li.Include(
pi=>pi.Id,
pi=>pi[“标题”],
pi=>pi[“应用程序”],
pi=>pi[“URL”],
pi=>pi[“AIR\u x0020\u ID”]
));
clientContext.ExecuteQuery();
List listofapplications=新列表();
foreach(collListItem中的ListItem oListItem)
{
{Console.WriteLine(oListItem[“Title”]+,Application“+oListItem[“Application”]);}
}
Console.ReadLine();
}
它给出了foreach处的错误(collListItem中的Listitem oListItem):
“Microsoft.SharePoint.Client.CollectionNotInitializedException”类型的异常
在Microsoft.SharePoint.Client.Runtime.dll中发生,但未被删除
用用户代码处理
其他信息:集合尚未初始化。信息技术
尚未请求或请求尚未执行。可能
需要明确要求
以下是详细的错误:
Microsoft.SharePoint.Client.CollectionNotInitializedException被删除
未经用户代码处理的HResult=-2146233079消息=集合
尚未初始化。尚未请求或请求已被取消
没有被执行。可能需要明确请求。Source=Microsoft.SharePoint.Client.Runtime StackTrace: 在Microsoft.SharePoint.Client.ClientObject集合'1.d_u0.MoveNext()中 在Home.btn\u中单击c:\Users\rakesh.a.srivastava\Documents\visualstudio中的(对象发送方,事件参数e) 2015\WebSites\DNSProvisioningPortal\Home.aspx.cs:第45行 在System.Web.UI.WebControls.Button.OnClick(EventArgs e)中 位于System.Web.UI.WebControl.Button.RaisePostBackEvent(String eventArgument) 在System.Web.UI.WebControl.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 事件(参数) 位于System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument) 位于System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)
内部异常:
请注意,我在控制台应用程序中没有遇到任何问题,但asp.net按钮单击操作存在问题。我已经添加了客户端和Client.Runtime引用!我无法理解为什么它在控制台中工作,而不是在网站中。我是否缺少任何名称空间、引用?我已经引用了这些URL,但是没有任何东西告诉我关于我的问题。请帮忙。谢谢根据我的测试,有时我们可以忽略aspnet项目中的异常。(对于您的代码,您需要用Client_XXX替换[“XXX”]) 准备工作 通过NuGet package manager向project安装Microsoft.SharePointOnline.CSOM 我的测试代码: 首先是扩展方法(可选) 用我的代码替换你文章中的一些代码:
List list = clientContext.Web.Lists.GetByTitle("CustomList1");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>1200</RowLimit></View>";
ListItemCollection collListItem = list.GetItems(camlQuery);
clientContext.Load(collListItem, li => li.Include(
pi => pi.Client_Title
//pi => pi["Application"],
// pi => pi["AIR_x0020_ID"]
));
//clientContext.ExecuteQueryAsync();
Task t2 = clientContext.ExecuteQueryAsync();
await t2.ContinueWith((t) =>
{
foreach (ListItem oListItem in collListItem)
{
System.Diagnostics.Debug.WriteLine(oListItem.Client_Title);
}
});
List List=clientContext.Web.Lists.GetByTitle(“CustomList1”);
CamlQuery CamlQuery=新的CamlQuery();
camlQuery.ViewXml=“1200”;
ListItemCollection collListItem=list.GetItems(camlQuery);
Load(collListItem,li=>li.Include(
pi=>pi.Client\u Title
//pi=>pi[“应用程序”],
//pi=>pi[“AIR\u x0020\u ID”]
));
//clientContext.ExecuteQueryAsync();
任务t2=clientContext.ExecuteQueryAsync();
等待t2。继续((t)=>
{
foreach(collListItem中的ListItem oListItem)
{
系统、诊断、调试、写入(oListItem.Client_Title);
}
});
如果我们直接使用[“Title”],它将在aspnet中崩溃,但客户端不会站在我这边
我没有深入研究原因,也没有尝试自定义字段。我会在我有时间的时候做更多的研究你好,我没有看到客户的标题,我是否缺少一些参考资料<代码>使用系统;使用Microsoft.SharePoint.Client;使用系统安全;使用System.Threading.Tasks代码>错误:ListItem不包含客户端标题的定义,是否缺少任何引用我通过Nuget添加CSOM DLL,您可以尝试。我猜VS SharePoint模板中的本地DLL可能不是最新的,我不确定这一点。太好了,它起作用了!!!保留了您的代码并更新了我的DLL,现在一切都很顺利:)非常感谢:)我已将其标记为答案,不幸的是,它没有注册我的投票。对于所有面临此问题的人,请使用上述代码并删除所有sharepoint引用!从NuGet package manager中,搜索Microsoft.SharePointOnline.CSOM并安装!这应该可以解决问题。谢谢你,西娅!:)
List list = clientContext.Web.Lists.GetByTitle("CustomList1");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>1200</RowLimit></View>";
ListItemCollection collListItem = list.GetItems(camlQuery);
clientContext.Load(collListItem, li => li.Include(
pi => pi.Client_Title
//pi => pi["Application"],
// pi => pi["AIR_x0020_ID"]
));
//clientContext.ExecuteQueryAsync();
Task t2 = clientContext.ExecuteQueryAsync();
await t2.ContinueWith((t) =>
{
foreach (ListItem oListItem in collListItem)
{
System.Diagnostics.Debug.WriteLine(oListItem.Client_Title);
}
});