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)

'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)

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.

ExceptionCondition
ArgumentNullException

listUrl is null .

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
NoteNote

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.

Show: