7heViking
7heViking

Reputation: 7577

Get SharePoint lists from URL

I want to receive the lists from a specific site URL. I know how to get the lists from the current site, but what if it is a custom site URL?

Here is how I do to get the lists from the current site:

foreach(SPList list in SPContext.Current.Web.Lists)
{
    DdlLookupFieldTargetList.Items.Add(list.ToString());
}

an example og my input string could look like this: http://dkbdkb70la/sites/HelloWorld

I am using SharePoint 2007

BR

Upvotes: 0

Views: 820

Answers (1)

Erik Noren
Erik Noren

Reputation: 4339

If you're given the url you want to open directly, it's a simple matter:

using (SPSite site = new SPSite(inputStringUrl))
{
  using (SPWeb web = site.OpenWeb())
  {
    foreach(SPList list in web.Lists)
    {
      DdlLookupFieldTargetList.Items.Add(list.ToString());
    }
  }
}

Upvotes: 2

Related Questions