我正在尝试使用SPQuery从sharepoint的讨论板上获取最新的10篇帖子。我需要阅读[PostUrl] [主题] [正文] [LastModifyDate]?
请有人帮助我吗?
答案 0 :(得分:2)
尝试使用以下示例代码,它可以处理我的环境。
SPSite oSite = new SPSite("http://localhost/");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["DiscussionBoardList"];
SPQuery qry = new SPQuery();
qry.RowLimit = 10;
qry.Query = "<OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";
qry.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='Modified' />";
DataTable dt = oList.GetItems(qry).GetDataTable();
答案 1 :(得分:0)
尝试使用以下示例代码,它可以处理我的环境。
SPSite oSite = new SPSite("http://localhost/");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["DiscussionBoardList"];
SPQuery qry = new SPQuery();
qry.RowLimit = 10;
qry.Query = "<OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";
qry.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='Modified' />";
DataTable dt = oList.GetItems(qry).GetDataTable();