简体   繁体   English

如何使用CSOM发现与SPList一起使用的正确内部名称

[英]How can I discover the right internal names to use with a SPList using CSOM

I'm loading a SharePoint list using the client service object model (SharePoint 2013 on-premise). 我正在使用客户端服务对象模型(SharePoint 2013内部部署)加载SharePoint列表。 I'm using the following code: 我正在使用以下代码:

private void buttonRefreshOrders_Click(object sender, RoutedEventArgs e)
{
    using (var ctx = new ClientContext("http://sharepoint/ci/resources"))
    {
        var list = ctx.Web.Lists.GetByTitle("Resource Order Form Content");

        var query = new CamlQuery
                        {
                            ViewXml =
                                @"<Where><Or><Eq><FieldRef Name=""Status""></FieldRef><Value Type=""Text"">Approved</Value></Eq><IsNotNull><FieldRef Name=""Status"" /></FieldRef></IsNotNull></Or></Where>"
                        };

        var collListItem = list.GetItems(query);

        ctx.Load(collListItem);
        ctx.ExecuteQuery();

        if (collListItem.Count == 0)
        {
            MessageBox.Show(
                "No orders are currently within the queue.",
                "Information Center",
                MessageBoxButton.OK,
                MessageBoxImage.Information);
        }
        else
        {
            MessageBox.Show("Success!");

            foreach (var item in collListItem)
            {
                MessageBox.Show(item["Status"].ToString());
            }
        }
    }

}

I receive the exception: 我收到异常:

An unhandled exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException' occurred in Microsoft.SharePoint.Client.dll Microsoft.SharePoint.Client.dll中发生了类型为“ Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException”的未处理异常

Typically I believe this happens when the name being referenced in the following line doesn't match what's in SharePoint's backend: 通常,我相信当以下行中引用的名称与SharePoint后端中的名称不匹配时,会发生这种情况:

MessageBox.Show(item["Status"].ToString());

However I don't understand how that's the case here as I've used this exact same naming within my CamlQuery. 但是我不明白这里的情况,因为我在CamlQuery中使用了完全相同的命名。 I've also used SP Caml Query Helper 2013 and the field names appear to be correct. 我还使用了SP Caml Query Helper 2013 ,字段名称似乎正确。

How can I find the correct field names that I should be referencing? 如何找到应该参考的正确字段名?

Goto the list on your sharepoint site, goto list settings, then click on the column your looking to get the correct name of, it will then be in the address bar. 转到共享点站点上的列表,转到列表设置,然后单击要查找的列以获取正确的名称,然后它将在地址栏中。

EG: YourSite/_layouts/FldEdit.aspx?List={Guid}&Field=Cost%5Fx0020%5FCentre%5Fx0020%5FCode EG:YourSite / _layouts / FldEdit.aspx?List = {Guid}&Field = Cost%5Fx0020%5FCentre%5Fx0020%5FCode

in this case the name of the field you want is Cost_x0020_Centre_x0020_Code (%5F is an "_" %20 is a space, etc you may need to find out a list of these.) 在这种情况下,您想要的字段名称为Cost_x0020_Centre_x0020_Code(%5F是“ _”,%20是空格,等等,您可能需要找出这些列表)。

This isn't a complete list but it has most http://www.werockyourweb.com/url-escape-characters/ 这不是完整的列表,但其中包含大多数http://www.werockyourweb.com/url-escape-characters/

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

相关问题 如何使用CSOM模型获取SharePoint服务器日期时间? - How can I get SharePoint server datetime using CSOM model? 正在使用WINDOWS / system32 / LogFiles。 我如何发现正在使用什么程序? 如果是服务器,我也该如何使用它? - WINDOWS/system32/LogFiles in use. How can I discover what program is using it? If it's the server, how can I use it too? 如何将Unity与内部类一起使用? - How can I use Unity with internal classes? 如何发现嵌入式资源的“路径”? - How can I discover the “path” of an embedded resource? 如何发现第0代堆中的可终结对象? - How can I discover what finalizable objects are in the generation 0 heap? 如何发现C#索引器中使用的键? - How can I discover the keys used in a C# indexer? ProjectItemsEvents.ItemAdded:如何发现项目类型? - ProjectItemsEvents.ItemAdded: how can I discover the item type? 如何发现设备是否连接到特定的串行(COM)端口? - How can I discover if a device is connected to a specific serial (COM) port? 我如何发现该对象已附加到特定的对象上下文? - How can i discover that object is attached to specific Object Context? 如何发现计算机上存在的网络适配器? - How can i discover the network adapter that exist on my machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM