Question

Quelle est la différence entre:

SPSite.Url 

SPSite.RootWeb.Url

Si les deux sont identiques, ce qui est considéré comme une bonne pratique?

Était-ce utile?

La solution

I don't believe there is a difference in terms of what they return back (the string representation of the root URL of the site).

However, in the second case you are referencing both an SPSite and SPWeb object whereas in the first you are only referencing the SPSite object (so there might be some minor performance considerations if all you are looking for is the URL to the site).

In addition I would think the the context of the code you are writing would favor one over the other (e.g. if you have code that is scoped at the site level it would make more sense to just get the SPSite object Url; if your code was scoped at the web level (for example, doing something to the root SPWeb object and then traversing down to subsequent children webs) then referencing the rootweb.url would make more consistent sense to me).

In both cases you would need to make sure you are following proper disposal practices: http://msdn.microsoft.com/en-us/library/ms468609.aspx

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top