SPWeb.GetFile method (String)

Retrieves the file object located at the specified URL.

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

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