【问题标题】:Retrieving SharePoint view via a Url - Client Side Object Model通过 URL 检索 SharePoint 视图 - 客户端对象模型
【发布时间】:2015-01-12 10:49:39
【问题描述】:

我在查找如何通过客户端对象模型从视图中检索数据时遇到了一些麻烦。我有可用的列表视图的 URL,但我似乎无法通过它获取数据。我可以检索列表,但这只会返回默认视图,而不是特定视图。

View 类有一个 ViewCollection.GetById 的属性,但它要求一个 Guid,我也无法通过 Url 获取它。这有可能吗?我错过了什么吗?

【问题讨论】:

    标签: sharepoint office365 csom


    【解决方案1】:

    默认情况下,您可以通过以下方式检索View

    如何通过 URL 检索视图

    以下示例演示如何通过 Url 检索视图:

    using System.Linq;
    using Microsoft.SharePoint.Client;
    
    namespace SharePoint.Client.Utilities
    {
        public static class ViewExtensions
        {
            public static View GetViewByUrl(this List list,string viewUrl)
            {
                var ctx = list.Context;
                var result = ctx.LoadQuery(list.Views.Where(v => v.ServerRelativeUrl == viewUrl));
                ctx.ExecuteQuery();
                return result.FirstOrDefault();
            }
        }
    }
    

    用法

    var viewUrl = "/[site]/[web]/[list]/viewname.aspx";
    using (var ctx = new ClientContext(webUri))
    {
       var list = ctx.Web.Lists.GetByTitle(listTitle);
       var view = list.GetViewByUrl(viewUrl);
       Console.WriteLine(view.Title);
    }
    

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 2023-04-05
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多