Friday, August 21, 2015

Objective c SharePoint content fetch soap service

Hope whoever reading this article is familiar with SharePoint authentication using Objective c. If not checkout my post on Objective c SharePoint login service , to get better idea on connecting and getting authenticated to SharePoint Server.

Now, we are able to successfully get authenticated to the SharePoint. So, what's next? Obviously 'Fetching Content' from the SharePoint to display it in our application or for some other purpose. After that you may need operations like listed below.

  •  Create Folder
  •  Upload File
  •  Rename Content
  •  Tagging Files

Let's start with content fetching from the SharePoint. Unlike other CMS systems (like BOX, DropBOX), SharePoint have a structure called 'List'. A List is nothing but a start point where after creating that you can create/upload folders and files. To get better idea on List structure of SharePoint, please go through the SharePoint List structure documentation in Microsoft SharePoint official website.

SharePoint gives you SOAP services for all the operations like I have mentioned above that we need to do on our SharePoint content. This msdn link has the list of end points and soap services names and descriptions that SharePoint provides. As shown in that link the endpoint for getting list of SharePoint items is _vti_bin/lists.asmx. At this location you can see the request and response of the SharePoint SOAP service for GetListItems. GetListItems is the service that we are going to use to get List content from the SharePoint.

Let's have a look at the SOAP service in objective c for fetching list content.

This is the SOAP body that we need to pass at the time of service request. This type of xml SOAP body might be familiar to the developers who have an experience on consuming SOAP services. I am really sorry for putting the code as an image. I tried to copy paste my code but, this xml was colliding with my article html. Once I get a solution for this, I will definitely place the raw code so that If any one need it, they can directly copy paste the code.

Let's see this body in detail and you might have observed that I have used Objective c string placeholders(%@) in this body. First one is for the SharePoint list name. This List is the one on whose content we are interested about in our iOS application and for that only we have connected to SharePoint. The second placeholder is for the folder in that list we are interested about if we are. Here we need to talk about what is folder as we have already given list name, whose content we wanted to fetch. As I said List is the staring point of the directory structurte, where we can have our folders and files. All the time we don't need to fetch the entire list content. Some times we may just need content of one particular folder. In this case we need to mention the folder that we are interested.

Let's see some examples for list names and folder path that we need to parse from the SharePoint URL given to us as these two parameters are very important for the SOAP body.

Example Link - 1:
This is a typical SharePont link structure. All the SharePoint basic urls end with Forms/AllItems.aspx. Here 'examplelist' which is just before the Forms can be taken as the list name that the url is pointing to. 'examplelist' is the list name that we need to put in the SOAP body. The RootFolder parameter of the url tells us the folder in the 'examplelist' List, that we are interested about. So 'fol2' is the target folder name. If you can observe it is at the second level in the list as it is inside of another folder called 'fol1'.
So in this case as the list name and folder values are as shown below.

Example Link - 2:           

In this url there is no RootFolder parameter. It means we are interested directly on the 'examplelist' list content. In this case it's obvious that the folder parameter will be empty. So in this case as the list name and folder values are as shown below.

Example Link - 3:     

This example url is same as the url in the Example-1. The only difference is that target folder is at the root level of the examplelist list. 
So in this case as the list name and folder values are as shown below.

Hope now you have got complete picture on the two important values that we have to put in the GetListItems SOAP body(listname and Folder). The next important is the 'rowLimit' value. Let's see what this is. If we have so many folders/files (say around 2000) in our target list or folder whose content we are fetching, Obviously it's a bad practice to fetch all the content and display in the application. So, What we need here is called pagination. This 'rowLimit' parameter helps us for this pagination functionality. If you put 100 as the value, It will give you the 100 rows, means the first 100 assets in the root folder or in the root list. There is an option for querying the items in the target folder or list, which is not that important at this point of time as our mail goal is to first fetch the content.

Now, we understood how to call GetListItems SOAP service of SharePoint to fetch content. It's time to know about the response it throws. 

SharePoint GetListItems service throws a bunch of the below shown xml objects which are nothing but the folders and files in your SharePoint targeted list or folder. In this you can see the folder/file name, author, modified date etc....

Hope this article is useful to SharePoint newbies.

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