如何从sharepoint的讨论板上获得最新的10个帖子?

时间:2011-10-20 22:18:51

标签: sharepoint moss wss

我正在尝试使用SPQuery从sharepoint的讨论板上获取最新的10篇帖子。我需要阅读[PostUrl] [主题] [正文] [LastModifyDate]?

请有人帮助我吗?

2 个答案:

答案 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();