代码
private DataTable GetFilesData()
{
SPList list = GetList();
DataTable dt = CreateDatatable();
SPFolder f = null;
try
{
if (string.IsNullOrEmpty(_folderName))
f = list.RootFolder;
else
f = list.RootFolder.SubFolders[_folderName];
if (!string.IsNullOrEmpty(_subFolder))
f = f.SubFolders[_subFolder];
GetAllFiles(f, ref dt, list.ID.ToString("B"));
}
catch
{ }
return dt;
}
private void GetAllFiles(SPFolder f, ref DataTable dt, string listId)
{
SPListItem item;
foreach (SPFile file in f.Files)
{
item = file.Item;
DataRow dr = dt.NewRow();
dr["IconUrl"] = file.IconUrl; //item["DocIcon"];
string newTag = "";
if (file.TimeCreated.AddDays(2) > DateTime.Now)
newTag = "<img border='0' src='/_layouts/2052/images/new.gif'/>";
dr["NewTag"] = newTag;
dr["DocItemID"] = item.ID;
dr["DocListID"] = listId;
dr["FileRef"] = item["FileRef"];
dr["Title"] = item["Title"];
dr["Author"] = file.Author.Name;
dr["Created"] = item["Created"];
dr["Modified"] = item["Modified"];
dr["Category1"] = item["Category1"];
dr["Category2"] = item["Category2"];
dr["SecurityLevel"] = item["SecurityLevel"];
dr["BaseName"] = item["BaseName"];
dt.Rows.Add(dr);
}
foreach (SPFolder sf in f.SubFolders)
{
GetAllFiles(sf, ref dt, listId);
}
}