我想从SharePoint列表中获取最后一项,但由于我是SharePoint新手,因此我很难完成任何事情。首先,这个CAML API很难找到,然后我真的没有任何编程经验。
无论如何,这是我在ASPX页面中的逻辑。我想显示最后一项:
<html>
<head>
<meta name="WebPartPageExpansion" content="full" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />
<script runat="server" type="">
protected void sevak(object sender, EventArgs e)
string lastitem;
try {
using (SPSite objsite = new SPSite()) {
using (SPWeb objWeb = objSite.OpenWeb(....)) {
SPList objList = objWeb.Lists["List"];
SPQuery objQuery = new SPQuery();
objQuery.Query = "<OrderBy><FieldRef Name='Number' Ascending='False'/></OrderBy><RowLimit>1</RowLimit>";
objQuery.Folder = objList.RootFolder;
SPListItemCollection colItems = objList.GetItems(objQuery);
if (colItems.Count>0) {
lastitem=colItems[0];
}
}
}
}
catch (Exception ex) { }
return lastitem;
</script>
<SharePoint:CssLink runat="server"></SharePoint:CssLink>
<SharePoint:ScriptLink runat="server" language="javascript" name="core.js"></SharePoint:ScriptLink>
</head>
<body>
<form id="form1" runat="server">
<h1>T-Site</h1>
<p>
<asp:Button runat="server" Text="Submit" id="Button1" OnClick="sevak" OnClientClick="javascript:window:alert('Your Request for a document number has been received');"></asp:Button>
</p>
</body>
</form>
</html>
答案 0 :(得分:1)
用于CAML查询使用U2U CAML查询构建工具,它非常易于使用
第二,你必须在安装了SharePoint的服务器上执行你的对象模型代码逻辑是正确的,但我看到你的语法有问题
语法从这篇文章中获取帮助 http://www.a2zdotnet.com/View.aspx?Id=114