Showing posts with label edit. Show all posts
Showing posts with label edit. Show all posts

Tuesday, September 1, 2015

Objective C BOX API updating File/Folder tags

Objective C BOX API doesn't directly give you an option to update file/folder tags. Where as it gives option to update name and description of the items which are very important compared to tags. Through out this article If I say BOX item, that means whether a BOX file or folder.

In this article I am going to explain, how we can edit BOX API classes to achieve this functionality like updating tags of a file or folder. Before going to that, let's have a look at how we can edit the name of a BOX item (file/folder). Below is the sample code I have used in my application to rename a BOX item.


File Rename:

 BoxFilesRequestBuilder *fileRequestBuilder = [[BoxFilesRequestBuilder allocinitWithQueryStringParameters:@{@"fields" : @"name,type,description,tags,id,size,created_at,created_by,parent"}];

 fileRequestBuilder.name = fileName;    
    [[BoxSDK sharedSDK].filesManager editFileWithID:fileID requestBuilder:fileRequestBuilder success:^(BoxFile *file) {
        resultBlock(file,nil);      
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) {
        resultBlock(nil,error);
    }];


Folder Rename:


    BoxFoldersRequestBuilder *folderBuilder = [[BoxFoldersRequestBuilder alloc] initWithQueryStringParameters:@{ @"fields" : @"name,type,description,tags,id,size,created_at,created_by,parent"}];
    folderBuilder.name = folderName;
    
    [[BoxSDK sharedSDK].foldersManager editFolderWithID:folderID requestBuilder:folderBuilder success:^(BoxFolder *folder) {
        resultBlock(folder,nil);
        
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) {
        resultBlock(nil,error);

    }];




We use BoxFilesRequestBuilder to request updates on BOX files and BoxFoldersRequestBuilder to request updates on BOX folder items. We give this request to filesManger of BoxSDK for files and foldersManager of BoxSDK for folders to get the update done BOX items.

If you look at the above code for name update, there is a property called 'name' in the BoxFoldersRequestBuilder & BoxFilesRequestBuilder. But there is no property called 'tags'. So, all we need to do here is add property called 'tags' to these classes.


  • Add the following line in BoxItemsRequestBuilder.h file, which is the base class for both files and folders request builder classes.



                   @property (nonatomic, readwrite, strongNSArray *tags;

  • And the below three steps of code in the BoxItemsRequestBuilder.m file.



1. Before init method:


@synthesize tags = _tags;      

2. In initWithQueryStringParameters method:


_tags = nil;   

3. bodyParameters method:        


[self setObjectIfNotNil:self.tags forKey: @"tags" inDictionary:dictionary];  



Once you place this code, we will get options to update tags for BOX items as shown below.

fileRequestBuilder.tags = tagsArr;    
folderBuilder.tags = tagsArr;


Hope this article is useful to iOS developers using BOX API.

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

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.


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.