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
- Connect to the correct web service
- Know the correct document site (sub site) and document library you want to use
- Get the ID/Version for the Site/Library combination
- Know the data you want update, along with build the correct CAML statement
- 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,