// get the reference
SPSite site = new SPSite("http://localhost"); // this will point to the portal URL
SPWeb web = site.OpenWeb();
// get the context
PortalContext context = PortalApplication.GetContext(site.ID); // context got using the site GUID
Guid newsGuid = AreaManager.GetSystemAreaGuid(context, SystemArea.News);
Area newsarea = AreaManager.GetArea(context, newsGuid);
AreaListingCollection newscoll = newsarea.Areas["内部新闻"].Listings; // fetches all listings that are part of the current area
//output.Write(newscoll.Count+"
");
DataTable areaTable = new DataTable("IntranetList");
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.DateTime");
idColumn.ColumnName = "Date";
areaTable.Columns.Add(idColumn);
DataColumn fTitleColumn = new DataColumn();
fTitleColumn.DataType = System.Type.GetType("System.String");
fTitleColumn.ColumnName = "Title";
areaTable.Columns.Add(fTitleColumn);
DataColumn fURLColumn = new DataColumn();
fURLColumn.DataType = System.Type.GetType("System.String");
fURLColumn.ColumnName = "URL";
areaTable.Columns.Add(fURLColumn);
DataRow row = null;
for(uint i=0;i
row = areaTable.NewRow();
row["Date"] = newscoll[i].CreationDate ;
row["Title"] = newscoll[i].Title;
row["URL"] = newscoll[i].URL;
areaTable.Rows.Add(row);
}
DataRow[] areaRows = areaTable.Select(null,"Date DESC");
for(uint i=0;i<10;i++)
{
//output.Write(areaRows[i][1].ToString()+"
");
output.Write(""+"["+areaRows[i][0] +"]
"); //WriteToFile is a custom function used for debug logging to a file
else
output.Write(""+"["+areaRows[i][0] +"]
"); //WriteToFile is a custom function used for debug logging to a file
}
output.Write("
[更多项目新闻]");
参考资料:
排序方法来此 dudu 的 http://www.cnblogs.com/dudu/archive/2005/02/25/109317.html
新闻检索来此 harsh 的 http://blogs.msdn.com/harsh/archive/2005/07/26/443244.aspx
谢谢 dudu和harsh。