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
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

Posted 09-19-2007 7:49 AM by Derik Whittaker

[Advertisement]

Comments

DotNetKicks.com wrote Updating List Information in SharePoint via Web Services
on 09-19-2007 8:51 AM

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

chevy wrote re: Updating List Information in SharePoint via Web Services
on 09-22-2007 1:29 PM

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

i only can update 1 item at a time.

Lutz wrote re: Updating List Information in SharePoint via Web Services
on 09-25-2007 8:02 PM

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?

jon elsner wrote re: Updating List Information in SharePoint via Web Services
on 09-26-2007 11:22 AM

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>";

Christopher Steen wrote Link Listing - September 27, 2007
on 09-27-2007 10:30 PM

Link Listing - September 27, 2007

Christopher Steen wrote Link Listing - September 27, 2007
on 09-27-2007 10:42 PM

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

samuel wrote re: Updating List Information in SharePoint via Web Services
on 03-20-2008 7:47 PM

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

Derik Whittaker wrote re: Updating List Information in SharePoint via Web Services
on 03-20-2008 7:57 PM

@Samuel,

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

Rajiv wrote re: Updating List Information in SharePoint via Web Services
on 05-14-2008 3:27 AM

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

Side effects of drug lexapro. wrote Lexapro side effects.
on 07-27-2008 4:18 AM

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

Lipitor. wrote Lipitor and zeita.
on 08-16-2008 2:19 AM

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

VQCduXmnLdBqLna wrote re: Updating List Information in SharePoint via Web Services
on 05-28-2009 8:43 PM

doors6.txt;5;5

Jane wrote re: Updating List Information in SharePoint via Web Services
on 06-20-2009 9:20 PM

<a href= http://fishing+boats+for+sale+in.thanauts.info/ >fishing boats for sale in</a>  

<a href= http://astronomy+picture+of+day.thanauts.info/ >astronomy picture of day</a>  

<a href= http://the+lyrics+to+danny+boy.thanauts.info/ >the lyrics to danny boy</a>  

<a href= http://neck+stiff+treat.thanauts.info/ >neck stiff treat</a>  

<a href= http://picture+of+the+sidekick+3.thanauts.info/ >picture of the sidekick 3</a>  

<a href= http://hardcore+sex+clip.thanauts.info/ >hardcore sex clip</a>  

<a href= http://taco+dip+recipie.thanauts.info/ >taco dip recipie</a>  

<a href= http://rbc+centura+bank.thanauts.info/ >rbc centura bank</a>  

<a href= http://nero+express+free.thanauts.info/ >nero express free</a>  

<a href= http://food+service+job.thanauts.info/ >food service job</a>  

<a href= http://the+baby+in+womb.thanauts.info/ >the baby in womb</a>  

<a href= http://how+to+do+breakdance+moves.thanauts.info/ >how to do breakdance moves</a>  

<a href= http://a+forensic+accounting.thanauts.info/ >a forensic accounting</a>  

<a href= http://texas+secretary+of+states.thanauts.info/ >texas secretary of states</a>  

<a href= http://the+kelowna+rockets.thanauts.info/ >the kelowna rockets</a>  

<a href= http://education+consolidation+loans.thanauts.info/ >education consolidation loans</a>  

<a href= http://africa+culture+south.thanauts.info/ >africa culture south</a>  

<a href= http://what+do+you+see+pictures.thanauts.info/ >what do you see pictures</a>  

<a href= http://easy+free+knitting+patterns.thanauts.info/ >easy free knitting patterns</a>  

<a href= http://red+velvet+cakes.thanauts.info/ >red velvet cakes</a>

Arnie wrote re: Updating List Information in SharePoint via Web Services
on 06-20-2009 11:44 PM

<a href= http://laugh+now+cry+later+tattos.thanauts.info/ >laugh now cry later tattos</a>  

<a href= http://culture+of+france.thanauts.info/ >culture of france</a>  

<a href= http://teen+strip+tease.thanauts.info/ >teen strip tease</a>  

<a href= http://harris+county+sheriffs.thanauts.info/ >harris county sheriffs</a>  

<a href= http://give+peace+a+chance.thanauts.info/ >give peace a chance</a>  

<a href= http://e+fax+free.thanauts.info/ >e fax free</a>  

<a href= http://arcade+games+for+sale.thanauts.info/ >arcade games for sale</a>  

<a href= http://body+of+christ.thanauts.info/ >body of christ</a>  

<a href= http://songs+on+commercials.thanauts.info/ >songs on commercials</a>  

<a href= http://what+is+nessus.thanauts.info/ >what is nessus</a>  

<a href= http://hilton+hot+paris+photo.thanauts.info/ >hilton hot paris photo</a>  

<a href= http://in+over+my+head.thanauts.info/ >in over my head</a>  

<a href= http://unsecured+business+start+up+loans.thanauts.info/ >unsecured business start up loans</a>  

<a href= http://hummer+stretch+limos.thanauts.info/ >hummer stretch limos</a>  

<a href= http://pasadena+unified+schools.thanauts.info/ >pasadena unified schools</a>  

<a href= http://on+the+double+dutch.thanauts.info/ >on the double dutch</a>  

<a href= http://asbestos+in+lungs.thanauts.info/ >asbestos in lungs</a>  

<a href= http://kansas+site+myspace+com.thanauts.info/ >kansas site myspace com</a>  

<a href= http://american+idol+recaps.thanauts.info/ >american idol recaps</a>  

<a href= http://billy+blanks+boot+camp.thanauts.info/ >billy blanks boot camp</a>

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 5:50 AM

What is it,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 9:27 AM

I like your work!,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 1:02 PM

I bookmarked this guestbook.,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 4:36 PM

What is it,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 7:57 PM

Very interesting sites.,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-29-2009 11:16 PM

Nice,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-30-2009 2:37 AM

Incredible site!,

name wrote re: Updating List Information in SharePoint via Web Services
on 07-30-2009 6:00 AM

Great,

Jane wrote re: Updating List Information in SharePoint via Web Services
on 08-12-2009 7:10 PM
Manitra wrote re: Updating List Information in SharePoint via Web Services
on 08-21-2009 6:16 AM

Hello,

I'm quite new to CAML and was looking for the CAML equivalent of the following Sql statement :

UPDATE Customer SET FullName='John Doe' WHERE FullName='Jon Doe'

I could not guess how to build an arbitrary WHERE clause to the UPDATE. Btw, notice that I do not have a unique identifier to identify the row but it's a simple text column named 'FullName'.

Thanks for your help.

joseph wrote re: Updating List Information in SharePoint via Web Services
on 09-20-2009 3:53 AM
samanta wrote re: Updating List Information in SharePoint via Web Services
on 09-20-2009 5:31 AM
Heel wrote re: Updating List Information in SharePoint via Web Services
on 09-30-2009 9:38 AM

<a href= huffhausgermany.mseilsuz.cn >huff haus germany</a>  

<a h

Dominic wrote re: Updating List Information in SharePoint via Web Services
on 11-01-2009 9:19 AM

<a href= bulletballisticschart.uttosojz.cn >bullet ballistics chart</a>  

<a href= http://limegreendefaultlayou

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)