Webs.WebUrlFromPageUrl Method

Returns the URL of the parent site for the specified page URL.

Web Service: WebsWeb Reference: http://<Site>/_vti_bin/Webs.asmx

Syntax

<SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/WebUrlFromPageUrl", RequestNamespace:="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace:="http://schemas.microsoft.com/sharepoint/soap/", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function WebUrlFromPageUrl ( _
    pageUrl As String _
) As String

Dim instance As Webs
Dim pageUrl As String
Dim returnValue As String

returnValue = instance.WebUrlFromPageUrl(pageUrl)
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/WebUrlFromPageUrl", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public string WebUrlFromPageUrl (
    string pageUrl
)

Parameters

  • pageUrl
    A string that contains the absolute URL of the page.

Return Value

A string that contains the site URL.

Remarks

If the page URL is "http://Server_Name/Web_One/Web_Two/Web_Three/Lists/Events/Allitems.aspx", the WebUrlFromPageUrl method returns "http://Server_Name/Web_One/Web_Two/Web_Three". If the Web site does not exist on the server, the top-level site is returned.

Example

The following code example displays the site URL for a specified page URL.

Dim webService As New Web_Reference_Folder_Name.Webs()
webService.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim strPageUrl As String = "http://Server_Name/sites/Site_Name/Lists/Events/AllItems.aspx"

Dim strSiteUrl As String = webService.WebUrlFromPageUrl(strPageUrl)

MessageBox.Show(strSiteUrl)
Web_Reference_Folder_Name.Webs webService = new Web_Reference_Folder_Name.Webs();
webService.Credentials= System.Net.CredentialCache.DefaultCredentials;

string strPageUrl = "http://Server_Name/sites/Site_Name/Lists/Events/AllItems.aspx";

string strSiteUrl = webService.WebUrlFromPageUrl(strPageUrl);

MessageBox.Show(strSiteUrl);

See Also

Reference

Webs Class
Webs Members
Webs Web Service