zoukankan      html  css  js  c++  java
  • Displaying files from a specific folder using SPDataSource

    http://www.sharepointconfig.com/2010/11/displaying-files-from-a-specific-folder-using-spdatasource/

    This is a short post to show how you can use the SPDataSource to display items from a specific folder in a SharePoint document library. While the other parameters are fairly well documented on MSDN this isn’t very clear. Generally I don’t recommend the use of folders to separate data, I prefer a metadata based approach. In some cases, however, it makes sense such as when you need to manage permissions or approval for a group of documents (especially in SharePoint 2007 where you don’t have document sets). Looking at the parameters we can use (as shown below) to identify and locate the data it would appear that passing the name of the folder to the RootFolder property would achieve this.

    NameDescription
    WebURL An empty string for the root Web site. Otherwise, a string containing a server-relative URL.
    ListName The value of the SPList.Title property. You can also specify the list by setting the List property
    ListItemID A string representation of an integer such as the value of the SPListItem.ID property.
    RootFolder The value of the SPFolder.Name property.



    Unfortunately setting RootFolder to the name of a specific folder such as “Folder1” doesn’t have any effect. The trick is to also specify the name of the list and the folder such as “Project Documents/Folder1” as shown below:

    <SharePoint:SPDataSource ID="dsFolder"
        runat="server"
        IncludeHidden="true"
        DataSourceMode="List"
        UseInternalName="true"
        SelectCommand="&lt;View&gt;&lt;/View&gt;">
        <SelectParameters>
            <asp:Parameter Name="ListName" DefaultValue="Project Documents" />
            <asp:Parameter Name="RootFolder" DefaultValue="ProjectDocuments/Folder1" />
        </SelectParameters>
    </SharePoint:spdatasource>

    Also note that you can change the default behaviour to show both files and folders by specifying a value for the Scope property of the SPDataSource to one of the following SPViewScope values:

    Member nameDescription
    Default Show only the files and subfolders of a specific folder.
    Recursive Show all files of all folders.
    RecursiveAll Show all files and all subfolders of all folders.
    FilesOnly Show only the files of a specific folder.



    If you need the RootFolder parameter to be dynamic (e.g. based on metadata from the current page) you can use the technique described in my previous post on creating custom parameters for a SPDataSource. If you haven’t used the SPDataSource control before check out the SPDataSource documentation on MSDN. Chris O’Brian also has a good series titled SPDataSource every developers friend. It is a great way of quickly retrieving SharePoint data without writing C# code that can then be bound to ASP.NET controls such as the Repeater, ListView, GridView or DropDownList as well as the DataFormWebPart if you want to control the output using XSLT.

  • 相关阅读:
    Spring boot test
    SQL怎么输出前n个记录? n是中间计算得到的,不支持变量传递
    crontab 命令
    Python 素数判断;以及默尼森数
    精通Web Analytics 2.0 (1) 引言
    Python 编程小备忘
    Python 编辑器 tips
    Hadoop 权威指南学习1 (主要框架)
    ml的线性回归应用(python语言)
    python 学习5--matplotlib画图实践
  • 原文地址:https://www.cnblogs.com/frankzye/p/2128316.html
Copyright © 2011-2022 走看看