通过客户端对象模型获取DefaultView

发布于 2024-11-28 21:15:56 字数 1013 浏览 4 评论 0原文

我想通过客户端对象模型加载Sharepoint 列表默认视图字段(我使用的是Silverlight)。以下是我发现的一些相关内容(在 msdn 上):

  • List 具有属性 DefaultViewUrl [类型为 string]
  • List 具有方法 GetView(Guid)< /代码>
  • List 具有属性 Views [类型为 ViewCollection]
  • ViewCollection 具有方法 GetById(Guid)
  • ViewCollection 具有方法 GetByTitle(string)
  • View 具有属性 DefaultView [类型为 bool]

那是我能找到的一切。如您所见,没有直接获取 DefaultView 的方法(List 上缺少 DefaultViewId 属性或 GetByUrl(string) 方法>查看集合)。

在我看来,唯一的解决方案是迭代 List.Views 集合并检查每个 View 上的 DefaultView 属性。这有点……嗯,效率低下……

我错过了什么吗?有人看到一些直线孤立吗? 感谢您的想法。

I want to load fields of the default view for Sharepoint list through client object model (I am using Silverlight). Here are some relevant things I've found (on msdn here):

  • class List has property DefaultViewUrl [of type string]
  • class List has method GetView(Guid)
  • class List has property Views [of type ViewCollection]
  • class ViewCollection has method GetById(Guid)
  • class ViewCollection has method GetByTitle(string)
  • class View has property DefaultView [of type bool]

That's everything I was able to find. As you can see there is no direct way of getting DefaultView (there is missing DefaultViewId property on List or GetByUrl(string) method on ViewCollection).

Seems to me as the only solution is to iterate through List.Views collection and check DefaultView property on each View. Which is kind of...well, inefficient...

Did I miss something? Anyone see some straigh solition?
Thanks for ideas.

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

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

发布评论

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

评论(2

闻呓 2024-12-05 21:15:56

尝试使用 LINQ 语句进行 LoadQuery

例如:

private IEnumerable<View> viewQuery = null;
public void LoadDefaultView()
{
    using (ClientContext ctx = ClientContext.Current)
    {
        list = ctx.Web.Lists.GetByTitle("YourList");

        viewQuery = ctx.LoadQuery(list.Views
                   .Include(v => v.Title) // include more lamda statements here to populate View Properties
                   .Where(v => v.DefaultView == true));

        ctx.ExecuteQueryAsync(LoadDefaultViewSuccess, LoadDefaultViewFailure);
    }
}
private void LoadDefaultViewSuccess(object sender, ClientRequestSucceededEventArgs args)
{
    // should only be one View in views
    View defaultView = viewQuery.FirstOrDefault();

    // use default.Title here
}
private void LoadDefaultViewFailure(object sender, ClientRequestFailedEventArgs args)
{
    // handle failure here
}

此处的 MSDN SharePoint 2010 Silverlight COM 文章
http://msdn.microsoft.com/en-us/library/ee538971.aspx

Try LoadQuery using a LINQ statement

For Example:

private IEnumerable<View> viewQuery = null;
public void LoadDefaultView()
{
    using (ClientContext ctx = ClientContext.Current)
    {
        list = ctx.Web.Lists.GetByTitle("YourList");

        viewQuery = ctx.LoadQuery(list.Views
                   .Include(v => v.Title) // include more lamda statements here to populate View Properties
                   .Where(v => v.DefaultView == true));

        ctx.ExecuteQueryAsync(LoadDefaultViewSuccess, LoadDefaultViewFailure);
    }
}
private void LoadDefaultViewSuccess(object sender, ClientRequestSucceededEventArgs args)
{
    // should only be one View in views
    View defaultView = viewQuery.FirstOrDefault();

    // use default.Title here
}
private void LoadDefaultViewFailure(object sender, ClientRequestFailedEventArgs args)
{
    // handle failure here
}

MSDN SharePoint 2010 Silverlight COM article here
http://msdn.microsoft.com/en-us/library/ee538971.aspx

帝王念 2024-12-05 21:15:56

怎么样? SPList.DefaultView? SPList DefaultView 成员是 SPView 对象(不是 bool)

What about SPList.DefaultView? The SPList DefaultView member is an SPView object (not bool)

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