SPWeb.GetViewFromUrl Method

Gets a view of a list within the site based on 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 GetViewFromUrl ( _
    listUrl As String _
) As SPView
'Usage
Dim instance As SPWeb
Dim listUrl As String
Dim returnValue As SPView

returnValue = instance.GetViewFromUrl(listUrl)
public SPView GetViewFromUrl(
    string listUrl
)

Parameters

  • listUrl
    Type: System.String

    The absolute or site-relative URL of the list for which the view is retrieved.

Return Value

Type: Microsoft.SharePoint.SPView
The view of the list with the specified URL.

Exceptions

Exception Condition
ArgumentNullException

listUrl is null .

Examples

The following code example uses the GetViewFromUrl method to return a view and uses the view to return and display items.

Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Site_Name")
    Dim list As SPList = webSite.Lists("List_Name")

    Dim view As SPView = webSite.GetViewFromUrl("Lists/List_Name/View_Name.aspx")
    Dim listItems As SPListItemCollection = list.GetItems(view)

    Response.Write(SPEncode.HtmlEncode(listItems.Xml))
End Using
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oWebsite.GetViewFromUrl("Lists/List_Name/View_Name.aspx");
    SPListItemCollection collListItems = oList.GetItems(oView);
    Response.Write(SPEncode.HtmlEncode(collListItems.Xml));
}

Note

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.

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace