共用方式為


SPWeb.GetFile Method (String)

Retrieves the file object located at the specified URL.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Function GetFile ( _
    strUrl As String _
) As SPFile
'Usage
Dim instance As SPWeb
Dim strUrl As String
Dim returnValue As SPFile

returnValue = instance.GetFile(strUrl)
public SPFile GetFile(
    string strUrl
)

Parameters

Return Value

Type: Microsoft.SharePoint.SPFile
The file object with the specified URL.

Exceptions

Exception Condition
ArgumentNullException

strUrl is null .

ArgumentException

strUrl is or empty.

Remarks

This method calls the SPFile constructor with this and strUrl.

Examples

The following code example loads the default.aspx file.

SPFile file = web.GetFile(“default.aspx”);
    if(file.Exists) // here, this condition will return always false
    {
      // …
    }

See Also

Reference

SPWeb Class

SPWeb Members

GetFile Overload

Microsoft.SharePoint Namespace