This documentation is archived and is not being maintained.

SPWeb.GetViewFromUrl Method

Windows SharePoint Services 3

Returns a view of a list within the site based on the specified URL.

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

public SPView GetViewFromUrl(
	string listUrl
)

Parameters

listUrl
Type: System.String
A string that contains either an absolute URL or a site-relative URL.

Return Value

Type: Microsoft.SharePoint.SPView
An SPView object that represents the view of the list

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

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));
}
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 Best Practices: Using Disposable Windows SharePoint Services Objects.

Show: