SharePoint SPQuery类简单测试
关于简单对象模型的操作,希望对开发人员有帮助!
static void GoThroughList(SPList list, SPFolder folder, int level)
{
SPQuery query = new SPQuery();
query.Folder = folder;
SPListItemCollection items = list.GetItems(query);
if (items.Count == 0)
return;
for (int i = 0; i < level; i++)
Console.Write(" ");
foreach (SPListItem item in items)
{
if (item.FileSystemObjectType == SPFileSystemObjectType.Folder)
{
Console.WriteLine("[{0}]", item.Name);
GoThroughList(list, item.Folder, level + 1);
}
else
Console.WriteLine(item.Name);
}
}
SPWeb web = (new SPSite("http://moss/sites/hello")).OpenWeb();
SPList list = web.Lists["test"];
list.Lists.IncludeRootFolder = true;
GoThroughList(list, list.RootFolder, 0);