Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Retrieving List Information in Share Point

One common tasks that I have needed to do while working with SharePoint 2007 (MOSS) is to retrieve information in regards lists or libraries.  You need this information when you want to perform add, update, or delete functions when working with data from a document library. 

In today's post I will walk you though retrieving the list information.  We will be getting this list information via the Lists.asmx web service.

Like I said above, this is a common task for me, so I have made this a utility style method.  You will notice that I pass in 2 different parameters into this method.  The first one is an enumeration value that contain the names of my different sites/sub-sites.   The second one is the name of the document library that I an want to work with.

Code to pull out the list information:

/// <summary> /// Will query for the list information via the correct web service for the given document site and name /// </summary> /// <param name="documentSite">The site enum to use</param> /// <param name="documentLibraryName">The name of the library to hit. Cannot be null or empty</param> /// <returns></returns> public IListDataInformation GetListInformation( DocumentSite documentSite, string documentLibraryName ) { if ( string.IsNullOrEmpty( documentLibraryName ) ) { throw new ArgumentException( "The document library provided was not valid." ); } string baseUrl = "http://yourSiteNameHere"; string serviceDirectory = "_vti_bin"; string baseURL = string.Format("{0}/{1}/{2}", baseUrl, documentSite, serviceDirectory); Lists listService = BuildListsService( baseURL ); XmlNode listResponse = listService.GetList( documentLibraryName ); string listID = listResponse.Attributes["ID"].Value; // Provides the GUID id for the actual list string listVersion = listResponse.Attributes["Version"].Value; // Provides the version number for the actual ist return new ListDataInformation( listID, documentLibraryName, listVersion ); }
Code below is called by the code above to build us a valid instance of the web service.  This method here is public because it is actually part of another class.  The Lists return type is an instance of the Webservice object. public Lists BuildListsService(string baseURL) { if (string.IsNullOrEmpty(baseURL)) { throw new InvalidOperationException("The base URl was not populated correctly"); } Lists returnService = new Lists(); // Here I create a valid credential to get around an issue we are having used the default credentails. System.Net.ICredentials credential = new System.Net.NetworkCredential("UserName", "Password", "Domain"); returnService.Credentials = credential; // We are not using this at this point in time because there is an issue with 401 error with // some document libraries. Was not able to solve this so used the above for now. //returnService.Credentials = System.Net.CredentialCache.DefaultCredentials; returnService.Url = string.Format("{0}/{1}", baseURL, "Lists.asmx"); return returnService; }


Code Explained

  1. First thing we need to do is build a connection to the web service
  2. Once we have our web service instance we need to connect to the service via the GetLists method.  This will return an XmlNode object for use.
  3. After we have the XmlNode return value from the GetList method we need to pull out the ID and Version values.  To take a look at all the possible values/data that is returned via the GetList method simply do a listResponse.OuterXml call on the listResponse XmlNode.
  4. Lastly we build an instance of my ListDataInformation object.  This object is a simple object with 3 properties that hold the ID, name and version.

Here you have it, a pretty simple and straight forward way to retrieve different information about your Sharepoint List.

Till next time,

kick it on DotNetKicks.com


Posted 08-25-2007 8:42 PM by Derik Whittaker
Filed under: , ,

[Advertisement]

Comments

DotNetKicks.com wrote Retrieving List Information in Share Point
on 08-26-2007 9:33 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

15 Links Today (2007-08-27) wrote 15 Links Today (2007-08-27)
on 08-27-2007 11:20 AM

Pingback from  15 Links Today (2007-08-27)

SharePoint 2007 link love 08-29-2007 at Virtual Generations wrote SharePoint 2007 link love 08-29-2007 at Virtual Generations
on 08-29-2007 3:25 AM

Pingback from  SharePoint 2007 link love 08-29-2007 at  Virtual Generations

Buy cialis. wrote Cialis best price buy online.
on 08-07-2008 2:15 AM

Cialis dosage.

Tramadol. wrote Tramadol c.o.d delivery.
on 05-29-2009 11:52 PM

Tramadol and depression.

Phentermine online. wrote Generic phentermine.
on 05-30-2009 10:31 PM

Low cost phentermine. Phentermine without a prescription. Phentermine. Phentermine without prescription. Phentermine online purchase. Cheapest phentermine. Phentermine diet pill.

Pharma187 wrote re: Retrieving List Information in Share Point
on 06-09-2009 5:51 PM

Very nice site!

criticized notes wrote re: Retrieving List Information in Share Point
on 06-14-2009 8:37 PM

1950 policymakers decreases simulations processes

cycles yields pnas kyoto led wrote re: Retrieving List Information in Share Point
on 06-20-2009 11:53 AM

reconstructions trend thermal 20th

Pharmc596 wrote re: Retrieving List Information in Share Point
on 06-22-2009 3:20 PM

Very nice site!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)