• 学习:SharePoint 使用 SPQuery.Folder 查询文件夹中的数据(转)



     在SharePoint中通过SPQuery.Folder属性, 可以很方便的查询列表下文件夹中的数据, 下面介绍如何使用:
    •      SPQuery.Folder: Gets or sets the folder within a document library from which to return items in the query.
    •      Demo:
    using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
    {
    
        oWebsiteRoot.Lists.IncludeRootFolder = true;
        SPList oList = oWebsiteRoot.Lists["Document_Library_Name"];
        SPFolder oFolder = oList.RootFolder.SubFolders["Folder_Name"];
    
        SPQuery oQuery = new SPQuery();
        oQuery.Folder = oFolder;
        SPListItemCollection collListItems = oList.GetItems(oQuery);
    
        foreach (SPListItem oListItem in collListItems)
        {
            Response.Write(SPEncode.HtmlEncode(oListItem.File.Name) + 
              "<BR>");
        }
    }
    • SPFolder:
    SPSite oSiteCollection = SPContext.Current.Site;
    SPWebCollection collWebsites = oSiteCollection.AllWebs;
    foreach (SPWeb oWebsite in collWebsites)
    {
        SPFolderCollection collFolders = oWebsite.Folders;
    
        foreach (SPFolder oFolder in collFolders)
        {
            SPFileCollection collFiles = oFolder.Files;
    
            long lngTotalFileSize = 0;
    
            for (int intIndex = 0; intIndex < collFiles.Count; intIndex++)
            {
                lngTotalFileSize += collFiles[intIndex].Length;
            }
    
                Label1.Text += " Web: " + 
                    SPEncode.HtmlEncode(oWebsite.Name)
                    + " Folder: " +
                    SPEncode.HtmlEncode(oFolder.Name) + " Number: "
                    + oFolder.Files.Count +
                    " Size: " + lngTotalFileSize + "<BR>";
        }
        oWebsite.Dispose();
    

    }







    文章来源:


  • 相关阅读:
    C#不引用IWshRuntimeLibrary获取快捷方式目标位置
    chrome插件
    禁用右键菜单
    自定义创建右键菜单项目
    Win10怀旧--win7体验
    Win10隐藏托盘图标-注册表
    一些软件下载地址
    Win10锁屏与关机相关设置-注册表
    Winform开发中的窗体重复及灵活切换问题
    Winform开发中如何将数据库字段绑定到ComboBox控件
  • 原文地址:https://www.cnblogs.com/LeimOO/p/1530372.html
Copyright © 2020-2023  润新知