Getting Some SharePoint Object URL’s In C#

There have been some questions posted in the SharePoint development newsgroups about how to appropriately get some object URL’s in SharePoint.

Here are some examples:

[csharp]

public string GetListUrl(SPList oList)
{
if (oList.DefaultView == null)
{
return oList.ParentWeb.Url;
}
return (oList.ParentWeb.Url + “/” + oList.DefaultView.Url);
}

public string GetWebUrl(SPWeb oWeb)
{
return oWeb.Url;
}

private string GetCurRequestUrl()
{
string l_strCurRequest = this.Page.Request.Url.AbsoluteUri;
if (l_strCurRequest.IndexOf(“/”, 8) >= 0)
{
l_strCurRequest = l_strCurRequest.Substring(0, l_strCurRequest.IndexOf(“/”, 8));
}
return l_strCurRequest;
}

[/csharp]

Pretty simple, but there were some questions about it.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *