SilverLight 中的异步代码与 SharePoint

发布于 2025-01-08 14:41:46 字数 509 浏览 3 评论 0原文

我的代码有一些问题。我按下按钮后有 silverlight 按钮,我想加载文档库并获取有关该库中有多少项目的信息,我的代码是:

 var web = context.Web;
 List sharedDocumentsList = context.Web.Lists.GetByTitle("dokumenty");

 int i = sharedDocumentsList.ItemCount;

 context.Load(sharedDocumentsList);
 context.ExecuteQueryAsync(OnFileWriteSucceeded, OnFileWriteFailed);

但我仍然遇到同样的问题。

集合尚未初始化。尚未请求或请求尚未执行。可能需要明确请求

我如何获取 ItemCount。这只是一个简单的例子,我需要循环使用这个列表等等。但我需要解决这个主要问题。如何直接在按钮单击方法中使用此文档列表。

谢谢。

I have some problem with my code. I have silverlight button after I press button I want to load document library and get information about how many items are in this library co my code is:

 var web = context.Web;
 List sharedDocumentsList = context.Web.Lists.GetByTitle("dokumenty");

 int i = sharedDocumentsList.ItemCount;

 context.Load(sharedDocumentsList);
 context.ExecuteQueryAsync(OnFileWriteSucceeded, OnFileWriteFailed);

But I got still same problem.

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explixitly requested

How Can I get ItemCount. This is only a simple example I need to work with this list in cycle and so on. But I need to solve this main problem. How to work with this documentlist directly in button click method.

Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2025-01-15 14:41:46

这对我有用:

private List docList;
private void GetList()
{
    var context = new ClientContext(ApplicationContext.Current.Url);
    context.Load(context.Web);
    docList = context.Web.Lists.GetByTitle("dokumenty");
    context.Load(docList);
    context.ExecuteQueryAsync(GetListSucceded, GetListFailed);
}

private void GetListFailed(object sender, ClientRequestFailedEventArgs e)
{            
    Dispatcher.BeginInvoke(() => MyErrorFunction();
}

private void GetListSucceded(object sender, ClientRequestSucceededEventArgs e)
{
    Dispatcher.BeginInvoke(() => GetItemsCount());
}

private void GetItemsCount()
{
    MessageBox.Show(docList.ItemCount.ToString());
}

This works for me:

private List docList;
private void GetList()
{
    var context = new ClientContext(ApplicationContext.Current.Url);
    context.Load(context.Web);
    docList = context.Web.Lists.GetByTitle("dokumenty");
    context.Load(docList);
    context.ExecuteQueryAsync(GetListSucceded, GetListFailed);
}

private void GetListFailed(object sender, ClientRequestFailedEventArgs e)
{            
    Dispatcher.BeginInvoke(() => MyErrorFunction();
}

private void GetListSucceded(object sender, ClientRequestSucceededEventArgs e)
{
    Dispatcher.BeginInvoke(() => GetItemsCount());
}

private void GetItemsCount()
{
    MessageBox.Show(docList.ItemCount.ToString());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文