简体   繁体   English

从 C# 中的 GUID 获取 SharePoint 在线列表名称

[英]Get SharePoint online list name from GUID in C#

Why am I getting this error when I run the code below?当我运行下面的代码时,为什么会出现此错误?

Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException: 'The property or field 'Title' has not been initialized. Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException:“属性或字段“标题”尚未初始化。 It has not been requested or the request has not been executed.尚未请求或尚未执行请求。 It may need to be explicitly requested.'可能需要明确要求。

 public  string getInternalNameOfList(string siteURL, Guid listGUID)
    {
        string listName = "";
        ClientContext clientContextD = new ClientContext(siteURL);
        clientContextD.Credentials = _credentials;
        ListCollection listCollectionD = clientContextD.Web.Lists;

        clientContextD.Load(listCollectionD, lists => lists.Include(list => list.Id , list => list.Title, list => list.SchemaXml, list => list.TemplateFeatureId, list => list.Fields));
        clientContextD.ExecuteQuery();

        Web oWebsiteD = clientContextD.Web;

        clientContextD.ExecuteQuery();
        listName = clientContextD.Site.RootWeb.Lists.GetById(listGUID).Title;
        return listName;
    }


   

Try to change your code to the below:尝试将您的代码更改为以下内容:

List list = web.Lists.GetById(listGUID);
clientContextD.Load(list);
clientContextD.ExecuteQuery();
listName = list.Title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM