Posted by Adam Buenz
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:
C#:
-
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;
-
}
Pretty simple, but there were some questions about it.










