In my project, I have to get the SpListItemCollection of the splist by the url that user entered. However, I cannot get anything by just using it.

To get a SPListItemCollection:

1) get SPSite object (site collection)
2) get SPWeb object (sub site (optional))
3) get SPList object (Guid, list name...)

The URL I received:


Do you guy have any idea to split the URL to fill the items?


1 Answer 1


According to MSDN,

The URL that is passed to the SPSite constructor does not need to match a site collection URL exactly. See examples below.

The following code example returns the site collection that is located at http://Server_Name/sites/Site_Name even though the URL that is passed to the constructor does not match the site collection URL.

using (SPSite oSiteCollection = new SPSite("http://Server_Name/sites/Site_Name/Subsite_Name/default.aspx"))

So you can use as below and get site collection object....

SPSite oSiteCollection = new SPSite("http://aaa/bbb/ccc/ddd/eee/fff/Forms/AllItems.aspx");

From here you can get list items based on view/caml query etc....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.