Monday, August 24, 2015

Objective c Upload File SharerPoint Soap Service

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 'Upload File' functionality in the SharePoint from our iOS app, which is an essential functionality that we must give to our app users. Without this functionality our app will be like read only content. Which means, our app is not going to be interactive. Let's see 'Upload File' functionality for the SharePoint using Objective c and with the help of SharePoint SOAP services.


                         





The SOAP service end point for 'Upload File' is _vti_bin/copy.asmx. And SOAP action for this is given below.



http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems


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 upload a file to SharePoint. The SOAP body for 'Upload File' is as shown below.






By seeing at the SOAP body, we can observe that there are two string placeholders(%@). Let's see how and what to pass in these two parameters to get the uploading of file to SharePoint done from our iOS app using Objective c.

The first string placeholder(%@) is for the destination url of the new file that we are trying to upload to SharePoint. Let's say, below url is the root folder url, that means whose content we fetched for display purpose in the app.

http://basedomain.com/sharepoint/mylist/folder1

Here, 'mylist' is the list and 'folder1' is the root folder. Now, we want to upload a file named 'newfile.png' in the folder1. Then the destination url parameter value that we need it pass in the SOAP body is as shown below.

http://basedomain.com/sharepoint/mylist/folder1/newfile.png

The second string placeholder(%@) is for the base64 encoded data of the file we are trying to upload. That means, first we need to convert our file to NSData. Then we need to base64 encode it, which gives us a NSString. This string value we need to pass in the second string placeholder.

That's it. We have passed, where to upload(destination url) and what to upload(base64 file content). This is enough for this SOAP service body. Your file will be uploaded to your target folder successfully if you correctly pass these two parameters.


Hope this article is useful to SharePoint newbies.

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

No comments:

Post a Comment