惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
MyScale Blog
MyScale Blog
博客园 - Franky
The Cloudflare Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
The Blog of Author Tim Ferriss
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
J
Java Code Geeks
腾讯CDC
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
博客园 - 【当耐特】
美团技术团队
云风的 BLOG
云风的 BLOG

博客园 - Ipark

[SharePoint 2010 User Profile Service] 关于User Profile Service的一些提示 搬到博客堂了! [SharePoint WorkFlow InfoPath]在InfoPath表单内提交表单并启动工作流 [Live Writer Test]台南地震,海底光缆大面积中断,MSN登不上以及境外网站无法访问 [ECM IRM RMS - 1]WSS V3中的IRM解决方案概述 microsoft.com全新改版,告诉你MOSS的性能不是问题,她很好使!! [WSS V3 WorkFlow]利用Visual Studio开发WSS V3工作流视频资料 RMS SP2 & MOSS 2007开启文档管理新时代,让文档权限保护无处不在 在KPI列表中使用Excel Services发布的工作簿 3步完成Excel Services的初始化和使用(使用Excel Services的最简步骤) 应用SharePoint的Workflow须记住的10句话!(也许还有更多:) SharePoint 中的Workflow,你用着爽吗? MOSS-Excel Services-Udf(用户自定义函数)-SQLExcuteUdf 查询sql server数据的用户自定义函数 MOSS2007 B2TR 下载,安装指南以及SDK下载(all from ms sharepoint team) SharePoint Portal Server 2003 Search does't like .Net Framework 2.0!!! (for Error in PortalCrawl Web Service solution) WSS V3和MOSS2007的区别 讨论:为什么Web不行?Console可以?---为什么Document Library不行?Generic List可以?(MOSS2007) 《Microsoft Office SharePoint Server 2007 前瞻技术指南》第八章预览_Excel Services Windows Rights Management Services SP2 BETA下载
WSS V3 中用代码遍历列表的方法(支持文件夹的列表的项目遍历)
Ipark · 2006-07-18 · via 博客园 - Ipark

在WSS V3中列表(List)中是支持文件夹的,可以用文件夹来组织一个列表的项目。
WSS V3中列表的结构如下:

在WSS V3的对象模型中SPList下的所有列表项目和子文件夹都是SPListItem,只是SPListItem的ContentType不一样
    项目的ContentType.Name = Item
    文件夹的ContentType.Name = Folder

用SPQuery.Folder可以设置Query的文件夹,利用SPList.GetItems(SPQuery)可以得到相应文件夹下的项目(包括了文件夹)

遍历列表项目的时候需要做到:
1)遍历出文件夹的层级结构
2)得到每个文件夹下的ListItem并区分是Item还是Folder,如果是Folder则还需要继续向下遍历

根据以上的分析,利用递归来完成列表的遍历:

        public static void getlistitems(SPList templist,SPFolder tempfolder,string levelstring)
        
{
            
if (templist.RootFolder != tempfolder)
            
{
                Console.WriteLine(
" " + levelstring + "." + tempfolder.Name);
            }

            
else
            
{
                Console.WriteLine(levelstring 
+ "." + tempfolder.Name);
            }

            SPQuery myquery 
=new SPQuery();
            
if (tempfolder.SubFolders.Count != 0)
            
{
                myquery.Folder 
= tempfolder;
                
foreach (SPListItem tempitem in templist.GetItems(myquery))
                
{
                    
if (tempitem.ContentType.Name == "Item") Console.WriteLine(" " + levelstring + "." + tempfolder.Name + "." + tempitem.Title + "(Item)");
                    
if (tempitem.ContentType.Name == "Folder") getlistitems(templist, tempitem.Folder, " " + levelstring + "." + tempfolder.Name);
                }

            }

            
else
            
{
                myquery.Folder 
= tempfolder;
                
foreach (SPListItem tempitem in templist.GetItems(myquery))
                
{
                   Console.WriteLine(
"  " + levelstring + "." + tempfolder.Name + "." + tempitem.Title+"(Item)");
                }

            }

        }

利用这个递归过程便利一个列表得到的结果: