Freigeben über


SPListItem.File-Eigenschaft

Ruft die durch das Element dargestellt Datei aus einer Dokumentbibliothek ab.

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

Syntax

'Declaration
Public ReadOnly Property File As SPFile
    Get
'Usage
Dim instance As SPListItem
Dim value As SPFile

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

Eigenschaftswert

Typ: Microsoft.SharePoint.SPFile
Ein Objekt, das die Datei darstellt. Gibt ein Nullverweis (Nothing in Visual Basic) in einer Dokumentbibliothek zurück, wenn das Element nicht vorhanden ist. Die File -Eigenschaft gibt auch ein Nullverweis (Nothing in Visual Basic) zurück, wenn das Element einen Ordner ist oder wenn das Element nicht in einer Dokumentbibliothek enthalten ist, obwohl es nicht empfohlen wird, dass Sie diese Eigenschaft in diesen Fällen aufrufen.

Beispiele

Das folgende Codebeispiel verwendet die File -Eigenschaft zum Anzeigen der Dateiname und checken Sie Status jeder XML-Datei in Freigegebene Dokumente, bei denen die Title Elementfeld einen angegebenen Wert enthält.

Hinweis

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

Hinweis

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.

Siehe auch

Referenz

SPListItem Klasse

SPListItem-Member

Microsoft.SharePoint-Namespace