This topic has not yet been rated - Rate this topic

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
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.
Exception Condition
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 (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 Disposing Objects.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ