0

The list "Region" exists at the parent web but the following code throws error. Is there anything else or other way I could reference a list that is on parent site?

SPList regionList = web.ParentWeb.GetList("Region");
2

The GetList method of a web object requires a url to the list. Here's what intellisense says:

Returns the list that is associated with the specified site-relative URL. A string that contains the site-relative URL for a list, for example, /Lists/Announcements.

So in your case, you may want to change your code snippet like the following:

SPList regionList = web.ParentWeb.GetList("/Lists/Region");
  • I am going to try this method in few and let you know. Thanks – lu A Jun 13 '11 at 14:48
0

I believe the SPWeb.GetList method uses a server-relative URL to get the list see here (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getlist.aspx).

You could add a using statement for the web and then get the list by it's name from the SPWeb.Lists collection:

Using (SPWeb web = web.ParentWeb)
{ SPList list = web.Lists["Region"]; }

Thanks,

Alex

  • I am going to try this method in few and let you know. Thanks – lu A Jun 13 '11 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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