You are here

You are here

Creating a zip archive and storing it in SpringCM

This sample shows how to create a zip archive where the resulting archive is placed in a SpringCM folder.  The scmDestinationFolder and destinationName must be specified.

Vertical Tabs

c#
//Here we are zipping a folder.  We could also give it a combo
//of a set of files and/or a set of folders
//Even if we don't send one of the object types, we must initialize it to an empty array
//In this example, we just zip a folder and put it in another target folder
string folderToZipId = "<This the Id of the folder we want to zip retrieved from other API calls>";
string targetFolderForFinalZipArchiveId = "<This the Id of the folder where the zip archive will be created>";
string zipArchiveFileName = "<The name of the zip archive, should have a .zip extension>";
 
//The API recall requires folder objects, not Id's
var folderToZip = new SCMFolder { Id = folderToZipId };
var targetFolderForFinalZipArchive = new SCMFolder { Id = targetFolderForFinalZipArchiveId };
 
//We will make the folder archive zip relative to the same folder we are zipping.  
//We could choose a folder higher up in the tree and the parent folders would be added to the archive
var folderToMakeZipArchiveRelativeTo = folderToZip;
 
//Create an SCMList of the documents and folders to be include in the zip
//In this case, just a single SpringCM folder's contents will be added
var nodesToZip = new SCMList { SCMDocuments = new SCMDocument[] { }, SCMFolders = new SCMFolder[] { folderToZip } };
 
//Initiate the request to create the zip archive and get the initial status
var requestToken = springCMService.FolderArchive(token, folderToMakeZipArchiveRelativeTo, nodesToZip, targetFolderForFinalZipArchive, zipArchiveFileName, null);
var result = springCMService.FolderArchiveGetStatus(token, requestToken);
 
//Keep checking every 10 seconds to see if zip is complete
while (result.Status != SCMQueueStatus.Success && result.Status != SCMQueueStatus.Failure)
{
	Thread.Sleep(10000);
	result = springCMService.FolderArchiveGetStatus(token, requestToken);
}
 
//See if we failed or had success in creating the zip archive
if (result.Status == SCMQueueStatus.Failure)
{
	Console.WriteLine("Folder Archive Failed - " + result.Message);
}
else
{
	//If we got this far, then we must have had success
	Console.WriteLine("Zip archive document with Id {0} and size {1} bytes was created.",result.ArchiveId,result.ArchiveSize);
}
java
//Here we are zipping a folder.  We could also give it a combo
//of a set of files and/or a set of folders
//Even if we don't send one of the object types, we must initialize it to an empty array
//In this example, we just zip a folder and put it in another target folder
String folderToZipId = "<This the Id of the folder we want to zip retrieved from other API calls>";
String targetFolderForFinalZipArchiveId = "<This the Id of the folder where the zip archive will be created>";
String zipArchiveFileName = "<The name of the zip archive, should have a .zip extension>";
 
//The API recall requires folder objects, not Id's
SCMFolder folderToZip = new SCMFolder();
folderToZip.setId(folderToZipId);
SCMFolder targetFolderForFinalZipArchive = new SCMFolder();
targetFolderForFinalZipArchive.setId(targetFolderForFinalZipArchiveId);
 
//We will make the folder archive zip relative to the same folder we are zipping.  
//We could choose a folder higher up in the tree and the parent folders would be added to the archive
SCMFolder folderToMakeZipArchiveRelativeTo = folderToZip;
 
//Create an SCMList of the documents and folders to be include in the zip
//In this case, just a single SpringCM folder's contents will be added
SCMList nodesToZip = new SCMList();
nodesToZip.setSCMDocuments(new SCMDocument[] { });
nodesToZip.setSCMFolders(new SCMFolder[]{folderToZip});
 
//Initiate the request to create the zip archive and get the initial status
String requestToken = springCMService.folderArchive(token, folderToMakeZipArchiveRelativeTo, nodesToZip, targetFolderForFinalZipArchive, zipArchiveFileName, null);
SCMFolderArchiveResult result = springCMService.folderArchiveGetStatus(token, requestToken);
 
//Keep checking every 10 seconds to see if zip is complete
while (result.getStatus() != SCMQueueStatus.Success && result.getStatus() != SCMQueueStatus.Failure)
{
	Thread.sleep(10000);
	result = springCMService.folderArchiveGetStatus(token, requestToken);
}
 
//See if we failed or had success in creating the zip archive
if (result.getStatus().equals(SCMQueueStatus.Failure))
{
	System.out.println("Folder Archive Failed - " + result.getMessage());
}
else
{
	//If we got this far, then we must have had success
	System.out.format("Zip archive document with Id %s and size %s bytes was created.",result.getArchiveId(),result.getArchiveSize());
}
php
<?php 
$SpringCM = new SoapClient('https://soapna11.springcm.com/atlas/webservices/v201305/SpringCMService.asmx?WSDL',array('trace'=>true);
$AuthResult = $SpringCM->AuthenticateNonDefault(array('userName' => '<your username>',
                                                  'password'  => '<your password>',
                                                  'AccountId' => '<your accountid>',
                                                  'apiKey'    => '<your api key>' ));
$token = $AuthResult->AuthenticateNonDefaultResult;
 
$basefolder =  new stdClass();
$basefolder->Id = '<folder to zip>';
 
$destinationfolder =  new stdClass();
$destinationfolder->Id = '<folder to zip>';
 
$folderToZip =  new stdClass();
$folderToZip->Id = '<folder to zip>';
 
$nodesToZip = new stdClass();
$nodesToZip->SCMDocuments = array();
$nodesToZip->SCMFolders = array($folderToZip);
$nodesToZip->TotalRowCount = 0;
 
try
{
   $requestToken = $SpringCM->FolderArchive(array( 'token' => $token, 
                                                    'baseFolder' =>$basefolder, 
                                                    'nodes' => $nodesToZip, 
                                                    'scmDestinationFolder' => $destinationfolder, 
                                                    'destinationName' => <zip file name>));
 
   $result = $SpringCM->FolderArchiveGetStatus(array('token' => $token, 
                                                      'requestToken' => $requestToken->FolderArchiveResult));
 
    echo $SpringCM->__getLastRequest();
 
    while($result->FolderArchiveGetStatusResult->Status != 'Success' && $result->FolderArchiveGetStatusResult->Status != 'Failure')
    {
      sleep(5);
      $result = $SpringCM->FolderArchiveGetStatus(array('token' => $token, 
                                                      'requestToken' =>$requestToken->FolderArchiveResult));
    }
 
    echo var_dump($result);
    echo var_dump($SpringCM->__getLastResponse());
}
catch(Exception $ex)
{
  echo $ex;
  echo $SpringCM->__getLastRequest();
}
?>