您的位置:首页 > 其它

Displaying files from a specific folder using SPDataSource

2011-08-05 10:42 513 查看
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
WebURLAn empty string for the root Web site. Otherwise, a string containing a server-relative URL.
ListNameThe value of the SPList.Title property. You can also specify the list by setting the List property
ListItemIDA string representation of an integer such as the value of the SPListItem.ID property.
RootFolderThe 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:

[code]<SharePoint:SPDataSource ID="dsFolder"

runat="server"

IncludeHidden="true"

DataSourceMode="List"

UseInternalName="true"

SelectCommand="<View></View>">

<SelectParameters>

<asp:Parameter Name="ListName" DefaultValue="Project Documents" />

<asp:Parameter Name="RootFolder" DefaultValue="ProjectDocuments/Folder1" />

</SelectParameters>

</SharePoint:spdatasource>


[/code]

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
DefaultShow only the files and subfolders of a specific folder.
RecursiveShow all files of all folders.
RecursiveAllShow all files and all subfolders of all folders.
FilesOnlyShow 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: