Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



Updating List Information in SharePoint via Web Services

In my continued learning on SharePoint and how to manipulate the data stored in SharePoint I thought I would post on how to perform updates on existing data inside a document library.

When performing an update on data inside of SharePoint there are a few steps that need to happen to make your journey a successful one.

Steps overview

  1. Connect to the correct web service
  2. Know the correct document site (sub site) and document library you want to use
  3. Get the ID/Version for the Site/Library combination
  4. Know the data you want update, along with build the correct CAML statement
  5. Perform the update via the web service

Connecting to the correct web service.
When performing an update you will want to connect to the Lists.asmx server.  You can get information about the web service here or if you have downloaded the latest SDK you can find information about the service inside there.



In the code above I am simply creating the service and providing it with the correct network credentials.  It may be possible for you to use System.Net.CredentialCache.DefaultCredentials in place of providing actual network credentials

Knowing the correct document site/document library
Any time you do anything with the SharePoint web service you will need to know the sub-site and document library.  This is because all the web services are isolated to a given sub-site and there are multiple locations for the service.  This is also why in the code above I provide the baseURL to connect to.  This URL is formatted as this
string.Format( "{0}/{1}/{2}", siteURL, DocumentSiteName, "_vti_bin" )

Get the ID/Version for the Site/Library
I found that in order to perform the update i needed to get the correct version/id for the given library that contains the data to be updated.  This information will be used during the actual update.

Build the CAML statement
To perform pretty much any action via the web services you will have to build a correct CAML statement.  You can get information on CAML here or check your SDK for info as well.

The CAML above is a very simple one.  This will update one field within a single row of data.  If you want to perform multiple updates you can do this, check your documentation for more information how.

Perform the actual update
Time to perform the actual update for the data. 


There you have it, a quick and dirty way to perform data updates via the Lists.asmx web service in SharePoint.

Till next time,


kick it on DotNetKicks.com


Comments

DotNetKicks.com said:

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

# September 19, 2007 8:51 AM

chevy said:

was just wondering how would i update mulitple item in a list with CAML?

i only can update 1 item at a time.

# September 22, 2007 1:29 PM

Lutz said:

This was very helpful, I can finally update my wiki pages programmatically. There's only one problem:

The Recent Changes does not show this page as changed even though the History of the page clearly shows the changes. Do you know whether any other fields apart from ID and WikiField need to be included in the CAML?

# September 25, 2007 8:02 PM

jon elsner said:

Do you know what the caml should be if one of the fields is a business data field.  I can't get the update to show for the test field below.  Thanks

strBatch = "<Method ID='1' Cmd='Update'>" +

"<Field Name = 'ID'>" + sFileIDinList  "</Field>" +

"<Field Name = 'test'>" + GetFullName(_file) +  "</Field>" +

"</Method>";

# September 26, 2007 11:22 AM

Christopher Steen said:

Link Listing - September 27, 2007

# September 27, 2007 10:30 PM

Christopher Steen said:

Finding A New Job, Week 2 - Observations From The Interview [Via: Jim Bolla ] Updating List Information...

# September 27, 2007 10:42 PM

samuel said:

I want to read data from a list of a sharepoint team site and write to a list on another team site on another server.. I am planning to use webservice.

If any has any idea how to write web service or any other procedure. Please Suggest me

# March 20, 2008 7:47 PM

Derik Whittaker said:

@Samuel,

You should be able to do this, you will simply have to repoint your webservice pointer to the new server/list.

# March 20, 2008 7:57 PM

Rajiv said:

Hi,

I need to use webservives provided by MOSS and also has to implement security to them.

For accessing list webservices exposed by MOSS, i have to <site URL>/_vti_bin/lists.asmx.

I need to know how i can secure these webservices, both transport level and message level security.

Any idea about this would be very helpful.

Cheers

# May 14, 2008 3:27 AM

Side effects of drug lexapro. said:

Lexapro side effects. Stop taking lexapro. Lexapro side-effects. Lexapro. Lexapro weight loss.

# July 27, 2008 4:18 AM

Lipitor. said:

Lipitor and its bad effects. Blood counts and lipitor. Side effects from lipitor. Lipitor. Lipitor side affects.

# August 16, 2008 2:19 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Red-Gate!