Pages

Jul 23, 2010

SPList.ParentWeb.Url & SPList.ParentWebUrl, are they really the same?

SPList.ParentWeb.Url & SPList.ParentWebUrl, are they really the same? or maybe not.
I was trying to get the Parent web url for a list that I have and noticed that they don’t really return the same Url.

Example:

You have a list Contacts on your root site http://myServer, and you got an instance of the SPList object for that list.

SPList.ParentWebUrl will return / where SPList.ParentWeb.Url will return http://myServer (which is what I really need)

MSDN says the following:

SPList.ParentWebUrl: Gets the URL of the parent Web site for the list.

SPList.ParentWeb.Url: Gets the absolute URL for the Web site.



So be careful of what you pick! Happy coding :-)