【问题标题】:Reading a SharePoint List in SharePoint Online Cross-Site Collection在 SharePoint Online 跨站点集合中读取 SharePoint 列表
【发布时间】:2017-07-02 00:07:54
【问题描述】:

我有一个函数在提供商托管的应用程序中运行(用 C# 编写并使用 CSOM)并访问我的 SharePointOnline 租户上的列表。

只要我从创建列表的网站集中访问提供程序托管的应用程序,该功能就会完全按照预期工作。

public bool CanUserReadList(ClientContext context, string listId)
    {
        try
        {                
            if (string.IsNullOrWhiteSpace(listId)) return false;

            List list = context.Web.Lists.GetById(new Guid(listId));                                                             
            context.Load(list, a => a.EffectiveBasePermissions,a=> a.DefaultViewUrl);
            context.ExecuteQuery();
            return list.EffectiveBasePermissions.Has(PermissionKind.OpenItems);
        }
        catch (Exception e)
        {
            //Error thrown if accessing from different site collection to 
        }
    }

但是,如果我从不同的网站集访问提供商托管的应用程序,我将无法访问列表(我得到一个未找到文件)异常。

如何使用 CSOM Microsoft.SharePoint.Client 库从另一个网站集中访问包含在一个网站集中的列表?

如何“跨站点收集”读取 CSOM/提供商托管应用程序中的列表?

“On-Prem”我会使用列表的 URL 打开 SPSite ...但到目前为止我在 CSOM/SharePointOnline 中尝试的所有操作都失败了。

【问题讨论】:

  • 我不确定在线环境。您是否尝试过为存在列表的站点集合创建上下文? ClientContext context = new ClientContext("SiteUrl");
  • 是的,我试过了——但失败并出现异常。问题是用户使用为其他网站集创建的上下文进入提供程序托管的应用程序。我需要能够为包含列表的 SiteCollection 创建一个上下文,或者以某种方式使用当前上下文访问列表

标签: c# sharepoint sharepoint-online csom provider-hosted


【解决方案1】:

尝试创建您尝试访问的站点集合的上下文。

ClientContext context = new ClientContext(“[Site URL]”);
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();

【讨论】:

    猜你喜欢
    • 2012-01-30
    • 2010-09-29
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 2016-08-27
    • 2012-04-18
    • 1970-01-01
    • 2016-08-29
    相关资源
    最近更新 更多