共用方式為


SPListItem.File property

取得文件庫項目所代表的檔案。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public ReadOnly Property File As SPFile
    Get
'用途
Dim instance As SPListItem
Dim value As SPFile

value = instance.File
public SPFile File { get; }

Property value

Type: Microsoft.SharePoint.SPFile
物件,代表的檔案。傳回a null reference (Nothing in Visual Basic)文件庫中,如果此項目不存在。File屬性也會傳回a null reference (Nothing in Visual Basic)如果項目] 資料夾,或者如果項目不在文件庫,但不建議您在下列情況下呼叫此屬性。

Examples

下列程式碼範例會使用File屬性來顯示的檔案名稱及取出狀態的每一個共用文件中,其中項目Title欄位包含指定的值的.xml 檔案。

注意事項注意事項

For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint.

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_Name"))
{
    SPList oList = oWebsite.Lists["Shared Documents"];

    string strSearch = "My Value";
    string strQuery = " <Where><And><Contains>" + 
        "<FieldRef Name='Title'/><Value Type='Text'>" + 
        strSearch + "</Value></Contains>" +
        "<Eq><FieldRef Name='File_x0020_Type'/>" +
        "<Value Type='Text'>xml</Value></Eq></And></Where>";

    SPQuery oQuery = new SPQuery();
    oQuery.Query = strQuery;

    SPListItemCollection collItemsRoot = oList.GetItems(oQuery);

    foreach (SPListItem oItemRoot in collItemsRoot)
    {
        if (oItemRoot.FileSystemObjectType == SPFileSystemObjectType.File)
        {
            Response.Write(SPEncode.HtmlEncode(oItemRoot.File.Name) + 
            " == " + oItemRoot.File.CheckOutStatus + "<BR>");
        }
    }

    SPListItemCollection collItemFolders = oList.Folders;

    foreach (SPListItem oItemFolder in collItemFolders)
    {
        oQuery.Folder = oItemFolder.Folder;

        SPListItemCollection collListItems = oList.GetItems(oQuery);

        foreach (SPListItem oListItem in collListItems)
        {
            if (oListItem.FileSystemObjectType == SPFileSystemObjectType.File)
            {
               Response.Write(SPEncode.HtmlEncode(oListItem.File.Name)+ 
                   " == " + oListItem.File.CheckOutStatus + "<BR>");
            }
        }
   }
}
Using oWebsite As SPWeb = SPContext.Current.Site.OpenWeb("Website_Name")
   Dim oList As SPList = oWebsite.Lists("Shared Documents")

   Dim strSearch As String = "My Value"
   Dim strQuery As String = " <Where><And><Contains>" & "<FieldRef Name='Title'/><Value Type='Text'>" & strSearch & "</Value></Contains>" & "<Eq><FieldRef Name='File_x0020_Type'/>" & "<Value Type='Text'>xml</Value></Eq></And></Where>"

   Dim oQuery As New SPQuery()
   oQuery.Query = strQuery

   Dim collItemsRoot As SPListItemCollection = oList.GetItems(oQuery)

   For Each oItemRoot As SPListItem In collItemsRoot
      If oItemRoot.FileSystemObjectType = SPFileSystemObjectType.File Then
         Response.Write(SPEncode.HtmlEncode(oItemRoot.File.Name) & " == " & oItemRoot.File.CheckOutStatus & "<BR>")
      End If
   Next oItemRoot

   Dim collItemFolders As SPListItemCollection = oList.Folders

   For Each oItemFolder As SPListItem In collItemFolders
      oQuery.Folder = oItemFolder.Folder

      Dim collListItems As SPListItemCollection = oList.GetItems(oQuery)

      For Each oListItem As SPListItem In collListItems
         If oListItem.FileSystemObjectType = SPFileSystemObjectType.File Then
            Response.Write(SPEncode.HtmlEncode(oListItem.File.Name) & " == " & oListItem.File.CheckOutStatus & "<BR>")
         End If
      Next oListItem
   Next oItemFolder
End Using
注意事項注意事項

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

請參閱

參照

SPListItem class

SPListItem members

Microsoft.SharePoint namespace