Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Tuesday, January 12, 2016

Objective C SharePoint User Permissions

In my earlier posts, we have seen fetching, creating and deleting content from SharePoint.We have also seen fetching user profile from SharePoint. 

At this point I feel like we forgot one important thing which is very munch needed to play with SharePoint content. Which is nothing but the permissions or the access level that logged in user has for entire list or for particular folder or file.


                         



Fetching permissions id very important before playing with content like creating folders, uploading documents and deleting documents. If user has only read only permissions, doing all the above actions which result in unauthorised operations.

So, instead of calling those services and waiting for their response to know whether user has permissions for that particular action, It is a good practice to fetch the permissions and then alerting the user before the operation.

Let's see how we can fetch user permissions for a list or a folder or a file item in SharePoint.

There are SOAP services available for fetching user role and permissions for a specific group and all. I am not going to discuss those. Where as we can simply get to know the use access level for each SharePoint item (folder/file) at the time of content fetch service response itself.


If we look at the content fetch xml response, It gives the metadata of an item as shown below.



This is the metadata for a folder named 'MyPics'. So, If you want to 

Create a folder  or
Upload a document or
Delete a document

in this folder, we need to check the ows_PermMask property. This value actually tells us the permission level of the user for this folder. Here it is 0x7fffffffffffffff. Which means full access.




                         


Here are the different access level codes in SharePoint.

0xb008431061    =>    Read Only
0x1b03c4312ef   =>    Contribute
0x1b03c431aef   =>    Edit
0x1b03c5f1bff    =>    Design
0x7fffffffffffffff  =>    Full Control

Hope this post is useful. Fell free to comment incase of any queries.

Monday, January 11, 2016

Objective C SharePoint User Profile Service

In my earlier posts we talked about authentication and fetching content from SharePoint using SOAP services. In this post let's look at fetching logged in user information from SharePoint as it is sometimes mandatory to display logged in user details like full name and email id etc.


                         



Let's have a look at the SOAP service details of user profile service.

SOAP BODY








If we look at the above SOAP body, there are no place holders. You may wonder how this service returns logged in user's profile without passing any user credentials. We need to pass credentials along with this service based on the SharePoint authentication mode.


SOAP ACTION

http://schemas.microsoft.com/sharepoint/soap/directory/GetCurrentUserInfo


END POINT

_vti_bin/UserGroup.asmx


Hope you are clear about the user profile service.

Let's have a look at the above service response now.





The response is gives all the required information about the logged in user like shown below.

  • Full name
  • UserID
  • Email
  • IsSiteAdmin etc




                         


Hope this post is useful. Fell free to comment in case of any queries.

Objective C SharePoint Service For Deleting An Item

So far In my earlier posts, We have seen authentication, content fetch, Create folder etc services for SharePoint using Objective C. Now let's looking at deleting items from our iOS app.

Here are the necessary SOAP service items to delete an item in the SharePoint.

SOAP BODY








This is the SOAP body message which is having 3 placeholders. Let's see what we need to pass in them.


  • List name :   The name of the list in which our item exists.
  • Change ID :   The change id of the item that we are going to delete.
  • File Path   :  The absolute path of the file item we are going to delete.

SOAP ACTION

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

END POINT

_vti_bin/lists.asmx


Just call this and have a look at the response to make sure your file has been deleted successfully. Your response may be varying based on your permissions.

If you have followed my earlier posts, this info is very much sufficient. 

So made it simple. Hope you have followed my earlier posts :)

Please not that this service is for deleting items from SharePoint not folders. We have another service for deleting folders from SharePoint.

Hope this post is useful.

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

Sunday, January 10, 2016

Objective C SharePoint Authentication Mode

SharePoint supports different types of authentication which we can set up in the server.
In my SharePoint Login service post, I have explained the process of login to SharePoint using the Windows authentication (BASIC authentication).

What if SharePoint is having "Forms" authentication?

Getting confused of these? What is this Windows and what is this Forms authentication and all?



                         


I am going to clear these things in a while in this post.

Before getting connected to any SharePoint sever it is a good practice to check the mode of authentication that server is having. As we know the SOAP services are a way to get connected to SharePoint and play with it's content and permissions, Let's have a look at fetching the authentication mode of a SharePoint server that we are trying to get connected.

Here it is:

SOAP BODY





SOAP ACTION

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

END POINT

_vti_bin/authentication.asmx

Here, I have mentioned only the necessary things to call the SOAP service. Hope I don't need to place the piece of code for calling the service and all. We are all Objective C experts and we know how to do it. Isn't it :)

Let's have a look at the response that the above SOAP service throws.


SOAP RESPONSE:









If you look at the ModeResult, the authentication mode here is "Forms". It throws "Windows" for windows based authentication.

So based on this response we need to change the login process to SharePoint.
In a way, it is just changing the passing of user credentials to all the SharePoint services.

Happy Login :)


                         



Hope this post is useful.

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.

Objective c Create Folder 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 'Create Folder' functionality in the SharePoint from our iOS app, which is a common functionality that we need to give to our app users. Let's see 'Create Folder' functionality for the SharePoint using Objective c and with the help of SharePoint SOAP services.

The SOAP service end point for 'CreateFolder' is _vti_bin/DWS.asmx. And SOAP action for this is given below. In this end point DWS stands for Document WorkSpace.



http://schemas.microsoft.com/sharepoint/soap/dws/CreateFolder


The SOAP action name itself says 'CreateFolder'. 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 create folder item. The SOAP body for 'CreateFolder' is as shown below.






By seeing at the SOAP body, we can observe that there is only one string placeholder(%@), which is the url of the new folder that we are trying to create. Let's see how and what to pass in this parameter with an example.

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 create a folder named 'newfolder' in the folder1. Then the parameter we need it pass in the SOAP body is as shown below.

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

That's it. This service is very simple. If there are any duplications in creating folder, the service response let's us know with the detailed description.

Hope this article is useful to SharePoint newbies.

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

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.


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

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.

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:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?RootFolder=/test/examplelist/fol1/fol2
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:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?           

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:


https://mydomain.com/test/examplelist/Forms/AllItems.aspx?RootFolder=/test/examplelist/fol1     

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.

Thursday, August 20, 2015

Objective c SharePoint login service

If you are trying to connect to SharePoint from an iOS application using Objective c, this article is for you. Unfortunately there is no enough information on the web regarding SharePoint connection from an iOS application using Objective c. Where as you can find well enough and better tutorials for an .Net application because, both are from same giant organisation like Microsoft. 

So it's easy for an .Net developer to quick start integrating SharePoint CMS in their .Net application. But, for an iOS developer it's a night mare. All we have is SharePoint SOAP services to communicate with the SharePoint.

Though, we are having REST services to connect to SharePoint, I am not supposed to talk about those because I don't have any experience on that. Here, I am going to give a quick start to connect to SharePoint. I mean first in place to get authenticated to SharePoint.

In SharePoint you can set different authentication mechanisms in the sever settings. Here I am going to show you a sample code to get connected to a SharePoint which is having BASIC authentication mechanism.

Let's talk about BASIC authentication first. If the SharePoint that you are trying to connect to is having a BASIC authentication mechanism in the server settings, You have to encode the user credentials while passing it to the server through a service for authentication.



                         




Here is the Objective c sample code to convert user credentials for BASIC authentication. 


    NSString *authStr = [NSString stringWithFormat:@"%@:%@", username, password];
    NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
    NSString *authValue = [authData base64EncodedStringWithOptions:0];

What I am doing in the above code is, I am taking username and password to a string with the separator as colon(:). Then I am doing the ASCII encoding of the string to convert it to
NSData. Finally I am doing base64 encoding and generating a BASIC authentication string of user credentials.

Here is the code to get user authentication to SharePoint. 


NSError *error = nil;
NSURLResponse *response;
            
NSURL *authenticationlURL = [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] 
                                                             objectForKey:@"SP_AUTHENTICATION_URL"]];            
            
            
NSString *authStr = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [authData base64EncodedStringWithOptions:0];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:authenticationlURL];
[request setValue:[NSString stringWithFormat:@"Basic %@",authValue] 
                                                                  forHTTPHeaderField:@"Authorization"];
[request setTimeoutInterval:60];
            
NSData *responseData = [NSURLConnection sendSynchronousRequest:request 
                                                  returningResponse:&response error:&error];

I am using normal NURLConnection class sendSynchronousRequest method only. I am giving the url as SharePoint base URL. We need to pass the 'Autherization' header with the value of the BASIC authentication string that we have generated.

That's all in coding. All you have to check is whether the status code of the response is coming as 200 or not to know whether the authentication is success or not. The response gives you some other values also. But at this point we don't need to worry about those values. If the status code is 200, it's like authentication is successful.

Hope this article is helpful to newbies to SharePoint.

Feel free to comment in case of any queries or comments.