Retrieve List Items from a different Site Collection in SharePoint 2010 -
i having issues retrieving list items different site collection. don't have issues when trying recieve list items within current site collection. example, http://myintranet.com/departments/it works. http://myintranet.com/sites/departments/it returns error.
if (!string.isnullorempty(sitename) && !string.isnullorempty(spcontext.current.web.url)) { spsecurity.runwithelevatedprivileges(delegate() { using (spsite intranetsite = new spsite(spcontext.current.web.url)) { using (spweb currentweb = intranetsite.allwebs["/sites/projects/physics"]) { splist postlist = currentweb.lists.trygetlist("issues"); if (postlist != null) { issuelist.datasource = postlist.items.getdatatable(); issuelist.databind(); } } } }); }
i haven't used different code when trying recieve list items. difference time getting list items site collection.
thanks help!
the problem intranetsite.allwebs
. spweb objects under current site collection.
you cannot infer site collection directly 1 site collection.
even though /sites/projects looks chid site collection /, it;s not. /sites managed path. / , /sites/projects @ same level of site collection hierarchy.
what need this:
if (!string.isnullorempty(sitename) && !string.isnullorempty(spcontext.current.web.url)) { spsecurity.runwithelevatedprivileges(delegate() { using (spweb currentweb = new spsite("http://server/sites/projects/physics").openweb()) { splist postlist = currentweb.lists.trygetlist("issues"); if (postlist != null) { issuelist.datasource = postlist.items.getdatatable(); issuelist.databind(); } } }); }
Comments
Post a Comment