Monday, August 24, 2015

Objective c Renaming Folder or File of a SharePoint content

Hope whoever reading this article is familiar with SharePoint authentication and content fetch using Objective c. If not checkout my posts on these using Objective c, to get better idea on connecting and getting authenticated and fetching content from SharePoint server. 

Objective c SharePoint login service
Objective c SharePoint content fetch soap service

Now we know how to fetch content from SharePoint. Let's say we have a rename functionality for the SharePoint assets in our iOS app, which is a common functionality that we need to give to our app users. Let's see renaming items(files/folders) in the SharePoint using Objective c and with the help of SharePoint SOAP services.

Like for content fetch the SOAP service end point for 'Rename' is _vti_bin/lists.asmx. And SOAP action for this is given below.

The SOAP action name itself says 'UpdateListItems', means we can update the list items using this SOAP service. Now, we know the end point of the SOAP service and the SOAP action, but the main thing here is the SOAP body which is the most crucial one. Let's have a look at the SOAP body and the parameters that we need to pass to rename an item(file/folder). The SOAP body for 'UpdateListItems' is as shown below.

By seeing at the SOAP body, we can observe that there are three string placeholders(%@). 

The first one is the listname. We all know what is this parameter. The name of the list on whose content we are doing this update operation.

The second placeholder is for the changeID of the item(file/folder). Don't get confused with 'itemID' and 'changeID'. I have wasted couple of days at the time of trying this rename functionality with itemID. There was no proper help or documentation also on what to pass, whether the itemID or changeID. SharePoint gives us both the values at the time of content fetch. For updates on list items(files/folders) we need to pass 'changeID' not 'itemID'. I am saving now couple of your's development time now by concluding that we have to pass changeID of the item :)

The third parameter is the new name that you want to keep for an item(file/folder). Remember, in case of file, this new name parameter should not include the extension. I mean, if your original file name is example1.png and you want to rename it as example2.png, you just need to pass example2.

Hope this article is useful to SharePoint newbies.

Feel free to comment in case of any queries/concerns.