SPWeb.GetFile Method (String)
Retrieves the file object located at the specified URL.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Parameters
- strUrl
- Type: System.String
The URL for the file.
| Exception | Condition |
|---|---|
| ArgumentNullException |
strUrl is null. |
| ArgumentException |
strUrl is or empty. |
Inconsistent, be careful
Given a sharepoint site where a file is at http://myserver/somesite/docs/myfile.txt you CAN open the file with:
$0new SPSite("http://myserver/").RootWeb.GetFile("somesite/docs/myfile.txt")$0
$0All looks dandy, file Exists=true. But if you try to call SaveBinary(byte[]) on the file it throws a DirectoryNotFoundException!$0
$0But if you open the file from the "somesite" SPWeb object instead, it will upload your file as expected.$0
$0$0
$0
$0Remember SPWeb.GetFile only works for files on that web.$0
=
- 3/10/2011
- klinkby
- 10/20/2011
- abraham1960