检索列表数据 [英] Retrieve List Data

查看:66
本文介绍了检索列表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用CAML和VS 2017检索SharePoint 2010列表数据。 


到目前为止我能够检索一些数据列。但是有些专栏我仍然无法获得数据。其中一些列是查找字段。并且有些列包含数据并且返回空。 


ID:1101

凭证编号:有值但返回空白¥
发起人:Microsoft.SharePoint.Client.FieldLookupValue -  查找字段(我需要检索值)


我正在测试c#控制台应用程序。但该项目需要某种WebAPI。 


这是我的代码: 

 string siteUrl = " HTTP://的TeamSite /位点/子网站/文件/英寸; 
string lstName =" Documents" ;;


ClientContext clientContext = new ClientContext(siteUrl);
List oList = clientContext.Web.Lists.GetByTitle(lstName);

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml ="< View>< Query>< Where>< / Where>< / Query>< ViewFields>< FieldRef Name ='Title'/>< FieldRef Name ='ID'/>< FieldRef Name ='Document_x0020_Number'/>< FieldRef Name ='City'/>< Value Type ='Text'>< / Value>< / ViewFields> < /视图>英寸;

ListItemCollection collListItem = oList.GetItems(camlQuery);

clientContext.Load(collListItem,
items => items.Include(
item => item [" Title"],
item => item [" ID"],
item => item [" Document_x0020_Number"],
item => item [" City"]));

clientContext.ExecuteQuery();

foreach(collListItem中的ListItem oListItem)
{
Console.WriteLine(" Title:{0} \ nID:{1} \ n凭证编号:{2城市:{3} \ n",
oListItem [" Title"],oListItem [" ID"],oListItem [" Document_x0020_Number"],oListItem [" City"]) ;
}

也许有更好的方法可以做到这一点。 


任何帮助都将非常感谢。  ;



解决方案


< span style ="font-size:10.5pt; font-family:'Segoe UI',sans-serif;颜色:#1F497D; background:white">要使用CSOM获取查阅列值,请参阅以下演示:

 FieldLookupValue lookup = item [" City"] as FieldLookupValue; 
string lvalue = lookup.LookupValue;
int lid = lookup.LookupId;




什么是"文档编号"列的列类型?


对于空数据问题,请确保您正在使用列的内部名称而不是显示名称。


要获取列的实际内部名称,请浏览库设置>编辑列并查看路径。 


路径如下:


< site> / _ layouts / FldEdit.aspx?List =%7B6DC46744%2D954D%2D4511%2D8E41%2D4AB8240495D8%7D& Field = Document%5Fx0020%5FNumber


'%5F'是' 。_"&NBSP;因此,我的"文档编号"列的内部名称是"Document_x0020_Number"。



如果它仍然返回空白,请提供有关"文档编号"列的更多信息。


最好的问候,


Linda Zhang



Hi,

I am trying to retrieve a SharePoint 2010 list data using CAML and VS 2017. 

So far I am able to retrieve a few data columns. But there are some columns I still cant get the data. Some of this columns are lookup fields. And some columns contain data and are returning empty. 

ID: 1101
Document Number: has value but is returning empty
Originator: Microsoft.SharePoint.Client.FieldLookupValue -  Lookup field (I need to retrieve the value)

I am testing on a c# console application. But the project needs to be some sort of WebAPI. 

Here is my code: 

string siteUrl = "http://teamsite/sites/subsite/documents/";
string lstName = "Documents";
           

            ClientContext clientContext = new ClientContext(siteUrl);
            List oList = clientContext.Web.Lists.GetByTitle(lstName);

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where></Where></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Document_x0020_Number' /><FieldRef Name='City' /><Value Type='Text'></Value></ViewFields></View>";

            ListItemCollection collListItem = oList.GetItems(camlQuery);

            clientContext.Load(collListItem,
                 items => items.Include(
                    item => item["Title"],
                    item => item["ID"],
                    item => item["Document_x0020_Number"],
                    item => item["City"]));

            clientContext.ExecuteQuery();

            foreach (ListItem oListItem in collListItem)
            {
                Console.WriteLine("Title: {0} \nID: {1}\n Document Number: {2}\n City: {3}\n", 
                    oListItem["Title"], oListItem["ID"], oListItem["Document_x0020_Number"], oListItem["City"]);
            }

Maybe there is a better way to do this. 

Any help will be very appreciated. 

解决方案

Hi,

To get the lookup column value using CSOM, please refer to the following demo:

FieldLookupValue lookup = item["City"] as FieldLookupValue;
string lvalue = lookup.LookupValue;
int lid = lookup.LookupId;


What is column type of the "Document Number" column?

For the empty data issue, please ensure you are using the internal name of column instead of the display name.

To get the actual internal name for your column, browsing to the library Settings > Edit Column and look at the path. 

The path will be like:

<site>/_layouts/FldEdit.aspx?List=%7B6DC46744%2D954D%2D4511%2D8E41%2D4AB8240495D8%7D&Field=Document%5Fx0020%5FNumber

'%5F' is the '_'.  So, the internal name of my "Document Number" column is "Document_x0020_Number".

If it still returns empty, please provide more information about your "Document Number" column.

Best Regards,

Linda Zhang


这篇关于检索列表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆