Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Getting Document Library List

  Asked By: Eliseo    Date: Sep 08    Category: Sharepoint    Views: 9151

How can I get the list of Document Library names and url, where I have the site
collection URL, programatically using C#



3 Answers Found

Answer #1    Answered By: Eliza Hutchinson     Answered On: Sep 08

using (SPSite site = new SPSite("http://localhost"))
using (SPWeb web = site.OpenWeb())
foreach (SPList currentList in web.Lists)
Console.WriteLine(currentList.Title+"\t"+Â currentList.URL);

Answer #2    Answered By: Lesley Tate     Answered On: Sep 08

actually there is nothing called currentList.URL as u mentioned in the code.

anyway I found another solution and here it is.

SPSite siteCollection = new SPSite("http://localhost");
SPWeb site = siteCollection.OpenWeb((siteCollection.RootWeb.ServerRelativeUrl));
SPListCollection listcollection = site.Lists;
for (int i = 0; i < listcollection.Count; i++)
SPList list  = listcollection[i];
if (list.BaseTemplate.ToString() ==
"DocumentLibrary") {
//document library  values here
string docTitle = list.Title; // title of the document  library

Answer #3    Answered By: Chris Daniel     Answered On: Sep 08

It is SPList.Url - it appears in the SDK documentation at
properties.aspx . You should really use the code sample from Zeeshan
instead of what you list, as your example does not properly cleanup the
open SPSite and SPWeb objects (the using() in the other sample does
this), and the siteCollection.RootWeb.ServerRelativeUrl parameter to the
SPWeb constructor is redundant.

Didn't find what you were looking for? Find more on Getting Document Library List Or get search suggestion and latest updates.

Related Topics:



Related Post