function UserList.GetUserName(_UserID:string): string;
const
// 这两个GUID至关重要,它们是从SharePoint Page上取出的,用于标识列表和视图
guidUsers : String = '{923D3FCF-070F-4896-8481-90FAFBA62E41}';
guidView : String = '{101ECD84-E59A-4BDF-A579-41A1A2670EE1}';
var
uname: String := string.Empty;
list : Lists := new Lists();
// 转化为CAML的查询语句,其原型是 "Where [User ID] = _UserID"
condition : String := string.Format('<Where><Eq><FieldRef Name=''User_x0020_ID'' /><Value Type=''Text''>{0}</Value></Eq></Where>', _UserID);
// 需要返回的字段,同样是以CAML的形式出现
need : string := '<FieldRef Name=''Title'' />';
xn : XmlNode := new XmlDocument();
s: Stream;
xr : XmlReader;
begin
try
list.Url := self.WebServiceLink;
list.Credentials := defCredential;
// 调用查询方法
self.getItemsValues(list, guidUsers, guidView, need, condition, '1', out xn);
s := new MemoryStream(ASCIIEncoding.Default.GetBytes(xn.OuterXml));
xr := XmlReader.Create(s);
while (xr.Read()) do
begin
// 取出指定列的内容,请注意这里的列同样是CAML,但是传入与传出时的写法不同
if ((XmlNodeType.Element = xr.NodeType) and (xr.Name = 'z:row')) then
uname := xr.GetAttribute('ows_Title').ToString();
end;
xr.Close();
s.Close();
result := uname;
except
on ex: Exception do
begin
Console.WriteLine(ex.Message);
result := string.Empty;
end;
end;
end;
在SharePoint中查询数据
最新推荐文章于 2022-08-30 11:26:08 发布