SPQuery.Folder property
取得或設定要從中傳回查詢中的項目在文件庫的資料夾。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Property Folder As SPFolder
Get
Set
'用途
Dim instance As SPQuery
Dim value As SPFolder
value = instance.Folder
instance.Folder = value
public SPFolder Folder { get; set; }
Property value
Type: Microsoft.SharePoint.SPFolder
SPFolder 物件,表示該資料夾。
Examples
下列程式碼範例會使用Folder屬性來指定要傳回的項目在文件庫的子資料夾。
注意事項 |
---|
如需有關如何使用 Language-Integrated 查詢 (LINQ) 查詢來擷取清單項目,在SharePoint Foundation中的資訊,請參閱Managing Data with LINQ to SharePoint。 |
這個範例要求using指示詞 (Imports Microsoft Visual Basic 中), Microsoft.SharePoint和Microsoft.SharePoint.Utilities命名空間。
Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
webSite.Lists.IncludeRootFolder = True
Dim list As SPList = webSite.Lists("Document_Library_Name")
Dim subFolder As SPFolder = _
list.RootFolder.SubFolders("Folder_Name")
Dim query As New SPQuery()
query.Folder = subFolder
Dim items As SPListItemCollection = list.GetItems(query)
Dim item As SPListItem
For Each item In items
Response.Write((SPEncode.HtmlEncode(item.File.Name) + "<BR>"))
Next item
Finally
webSite.Dispose()
End Try
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>");
}
}
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |