Cloud Storage Integrator - Online Help
Cloud Storage Integrator
Questions / Feedback?

Box Class

Properties   Methods   Events   Configuration Settings   Errors  

The Box component provide an easy way to upload, download, and manage files and folders with Box.com.

Syntax

Box

Remarks

The Box class provides a simple interface to working with Box.com. Capabilities include uploading and downloading files, strong encryption support, creating folders, moving and copying resource, and more.

To begin, first create an account and register your application with Box.com. Consult the Box.com documentation for instructions on this process.

Authentication

Authentication is performed via OAuth 2.0. Use the OAuth class included in the toolkit, or any other OAuth implementation to perform authentication and retrieve an authorization string. Once you've obtained an authorization string like:

Bearer ya29.AHES6ZSZEJzATdZYjeihDn5W-VrXSsxEZu5p0pclxGdKKQ
Assign this value to the Authorization property before attempting any operations. Consult the Box.com documentation for this particular service for more information about supported scope values and more details on OAuth authentication.

Listing Resources

ListResources lists resources within the account at the specified path.

ListResources lists resources in the folder specified by ResourceParentId. If ResourceParentId is unspecified the root folder contents will be listed.

After calling this method set ResourceIndex to a value from 0 to ResourceCount - 1. Setting ResourceIndex populates other Resource properties to provide information about the resource.

After calling this method the following resource properties are populated:

If the results are paged, the ResourceMarker property will be populated. Call this method again to retrieve the next page of results. When the last page of results is returned ResourceMarker will be empty.

Note: To define a specific list of fields which are returned in the response for each resource set the "fields" parameter via AddQueryParam. Refer to the Box documentation for a full list of available fields.


box.ResourceParentId = "123456";
box.ListResources();
for (int i = 0; i < box.ResourceCount; i++)
{
  box.ResourceIndex = i;
  Console.WriteLine(box.ResourceName);
}

Downloading Files

The DownloadFile method downloads a specific file.

DownloadFile downloads the file specified by ResourceId. Set ResourceId to the Id of the file to download before calling this method. If LocalFile is set the file will be saved to the specified location. If LocalFile is not set the file data will be held by ResourceData.

To decrypt an encrypted file set EncryptionAlgorithm and EncryptionPassword before calling this method.


box.ResourceId = "50619395801"
box.LocalFile = "../MyFile.zip";
box.DownloadFile();

Resuming Downloads

The class also supports resuming failed downloads by using the StartByte property. If the download was interrupted, set StartByte to the appropriate offset before calling this method to resume the download.


box.ResourceId = myId;
box.LocalFile = downloadFile;
box.DownloadFile();

//The transfer is interrupted and DownloadFile() above fails. Later, resume the download:

//Get the size of the partially download file
box.StartByte = new FileInfo(downloadFile).Length; 
box.ResourceId = myId;
box.LocalFile = downloadFile;
box.DownloadFile();

Resuming Encrypted File Downloads

Resuming encrypted file downloads is only supported when LocalFile was set in the initial download attempt. When beginning an encrypted download if LocalFile is set the class will create a temporary file in TempPath to hold the encrypted data until it is complete.

If the download is interrupted DownloadTempFile will be populated with the temporary file holding the partial data. When resuming, DownloadTempFile must be populated along with StartByte to allow the remainder of the encrypted data to be downloaded. Once the encrypted data is downloaded it will be decrypted and written to LocalFile.

box.ResourceId = myId;
box.LocalFile = downloadFile;
box.EncryptionPassword = "password";
box.DownloadFile();

//The transfer is interrupted and DownloadFile() above fails. Later, resume the download:

//Get the size of the partially download temp file
box.StartByte = new FileInfo(box.Config("DownloadTempFile")).Length; 
box.ResourceId = myId;
box.LocalFile = downloadFile;
box.EncryptionPassword = "password";
box.DownloadFile();

Uploading Files

UploadFile uploads a file to the folder specified by ResourceParentId. If ResourceParentId is not specified the file will be uploaded to the root directory. This method returned the Id of the uploaded file. If the file already exists the server will return an error.

The FileName parameter specifies the name of the file. Naming restrictions:

  • Names must be 255 characters or less.
  • Names with non-printable ASCII are not supported.
  • Names with the characters "/", "\", or trailing whitespace are not supported.
  • The special names "." and ".." are not supported.

LocalFile specifies the file to upload. The data to upload may also be set in ResourceData or set by SetUploadStream. To encrypt a file set EncryptionAlgorithm and EncryptionPassword.

The following properties are applicable when calling UploadFile:


box.LocalFile = "../MyFile.zip";
box.UploadFile("MyFile.zip");

After uploading a file the Resource* properties are populated with information about the uploaded file.

Additional Functionality

The Box class offers advanced functionality beyond simple uploads and downloads. For instance:

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

AccountAddressThe user's physical address.
AccountCreatedDateThe time at which the user was created.
AccountEmailThe Email address of the user.
AccountIdThe unique identifier for this user.
AccountMaxFileSizeThe maximum individual file size the user can have in bytes.
AccountModifiedDateThe date which the user was last modified.
AccountMyTagsA comma separated list of tags used in all files ands folders owned by the user.
AccountNameThe name of the user.
AccountPhoneThe user's phone number.
AccountRoleThe role of the user.
AccountStatusThe status of the user.
AuthorizationOAuth 2.0 Authorization Token.
EncryptionAlgorithmThe encryption algorithm.
EncryptionPasswordThe encryption password.
FirewallAutoDetectThis property tells the component whether or not to automatically detect and use firewall system settings, if available.
FirewallTypeThis property determines the type of firewall to connect through.
FirewallHostThis property contains the name or IP address of firewall (optional).
FirewallPasswordThis property contains a password if authentication is to be used when connecting through the firewall.
FirewallPortThis property contains the TCP port for the firewall Host .
FirewallUserThis property contains a user name if authentication is to be used connecting through a firewall.
LocalFileThe location of the local file.
LocalHostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
MetadataFieldCountThe number of records in the MetadataField arrays.
MetadataFieldNameThe name of the property.
MetadataFieldUpdateOpThe update operation to perform.
MetadataFieldValueThe value of the property.
OverwriteWhether to overwrite the local or remote file.
ProxyAuthSchemeThis property is used to tell the component which type of authorization to perform when connecting to the proxy.
ProxyAutoDetectThis property tells the component whether or not to automatically detect and use proxy system settings, if available.
ProxyPasswordThis property contains a password if authentication is to be used for the proxy.
ProxyPortThis property contains the TCP port for the proxy Server (default 80).
ProxyServerIf a proxy Server is given, then the HTTP request is sent to the proxy instead of the server otherwise specified.
ProxySSLThis property determines when to use SSL for the connection to the proxy.
ProxyUserThis property contains a user name, if authentication is to be used for the proxy.
QueryParamsCountThe number of records in the QueryParams arrays.
QueryParamsNameThis property contains the name of the parameter to be used in a Query request.
QueryParamsValueThis property contains the value of the parameter to be used in a Query request.
ResourceCountThe number of files and folders.
ResourceCreatedByThe email of the creator of the resource.
ResourceCreatedDateThe date on which the resource was created.
ResourceDataHolds the file data after downloading or sets the file data before uploading or updating.
ResourceDeletedWhether the resource is deleted.
ResourceDeletedDateThe date on which the resource was deleted.
ResourceDescriptionA short description of the file or folder.
ResourceETagThe ETag of the resource.
ResourceHashThe SHA1 hash of the file.
ResourceIdThe unique identifier of the resource.
ResourceIndexSelects the file or folder.
ResourceMarkerA marker when list results are paged.
ResourceModifiedByThe email of the user who last modified the resource.
ResourceModifiedDateThe date on which the resource was modified.
ResourceNameThe name of the resource.
ResourceOwnerThe email of the resource owner.
ResourceParentIdThe Id of the parent resource.
ResourcePurgedDateThe date on which the resource will be permanently deleted.
ResourceRevisionThe revision of the file.
ResourceSizeThe size of the resource in bytes.
ResourceSyncStateThe sync state of the folder.
ResourceTagsA comma separate list of tags.
ResourceTypeIndicates whether the current entry is a folder or a file.
SearchMarkerA marker when searches are paged.
SharedResourceAccessThis property specifies the type of access granted to a shared link.
SharedResourceCanDownloadWhether downloads are allowed.
SharedResourceCanPreviewWhether the resource can be previewed.
SharedResourceDownloadURLA direct download link.
SharedResourcePasswordThe password to protect the resource.
SharedResourcePasswordRequiredWhether the link is protected by a password.
SharedResourceUnsharedDateThe date at which the resource will no longer be shared.
SharedResourceURLThe URL of the link.
SSLAcceptServerCertEncodedThe certificate (PEM/base64 encoded).
SSLCertEncodedThe certificate (PEM/base64 encoded).
SSLCertStoreThe name of the certificate store for the client certificate.
SSLCertStorePasswordIf the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.
SSLCertStoreTypeThe type of certificate store for this certificate.
SSLCertSubjectThe subject of the certificate used for client authentication.
SSLServerCertEncodedThe certificate (PEM/base64 encoded).
StartByteThe byte offset from which to start the upload or download.
ThumbnailFormatThe thumbnail format.
ThumbnailSizeThe size of the thumbnail in pixels.
TimeoutA timeout for the component.
TotalSpaceThe total allowed space in bytes.
UsedSpaceThe amount of space used in bytes.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

AddQueryParamAdds a query parameter to the QueryParams properties.
ConfigSets or retrieves a configuration setting .
CopyResourceCopies the specified resource to a new location.
CreateFolderCreates a folder with the specified name.
CreateMetadataCreates metadata for a file.
DeleteMetadataDeletes all metadata for a file.
DeleteResourceDeletes the specified resource.
DownloadFileDownloads a file.
GetAccountInfoRetrieves information about the current user account.
GetMetadataRetrieves metadata for the file.
GetPreviewLinkGets a link that may be used to preview the resource.
GetResourceInfoRetrieves information about the specified resource.
GetSharedResourceInfoGets information about a shared resource.
GetThumbnailRetrieves a thumbnail image of the current resource.
InterruptInterrupt the current method.
ListDeletedResourcesLists deleted resources.
ListResourcesLists the resources in the specified folder.
ListRevisionsLists revisions for a file.
LockFileLocks the specified file.
PromoteRevisionPromotes a specific revision of a file to the current version.
RestoreResourceRestores a deleted resource.
SearchThis method searches resources for the specified query.
ShareResourceShares the specified file or folder.
UnlockFileUnlocks the specified file.
UnshareResourceStops sharing a resource.
UpdateMetadataUpdates metadata fields for a file.
UpdateResourceUpdates the file or folder.
UploadFileUploads a file.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

EndTransferFired when a document finishes transferring.
ErrorInformation about errors during data delivery.
ResourceListFired for each resource listed.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.
StartTransferFired when a document starts transferring (after the headers).
TransferFired while a document transfers (delivers document).

Configuration Settings


The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

DownloadTempFileThe temporary file used when downloading encrypted data.
IncludeFileHashWhether to include the SHA1 hash when uploading a file.
MaxResultsThe maximum number of results to return when searching or listing resources.
ResourceClientCreatedDateA client assigned creation date.
ResourceClientModifiedDateA client assigned modified date.
RetryAfterThe number of seconds after which to retry the request.
TempPathThe path to the directory where temporary files are created.
EncryptionIVThe initialization vector to be used for encryption/decryption.
EncryptionKeyThe key to use during encryption/decryption.
XPathProvides a way to point to a specific element in the returned XML response.
XElementThe name of the current element.
XParentThe parent of the current element.
XSubTreeA snapshot of the current element in the document.
XTextThe text of the current element.
XChildCountThe number of child elements of the current element.
XChildName[x]The name of the child element.
XChildXText[x]The inner text of the child element.
AcceptEncodingUsed to tell the server which types of content encodings the client supports.
AllowHTTPCompressionThis property enables HTTP compression for receiving data.
AllowIdenticalRedirectURLAllow redirects to the same URL.
AppendWhether to append data to LocalFile.
AuthorizationThe Authorization string to be sent to the server.
BytesTransferredContains the number of bytes transferred in the response data.
EncodeURLIf set to true the URL will be encoded by the component.
FollowRedirectsDetermines what happens when the server issues a redirect.
GetOn302RedirectIf set to true the component will perform a GET on the new location.
HTTPVersionThe version of HTTP used by the component.
IfModifiedSinceA date determining the maximum age of the desired document.
KeepAliveDetermines whether the HTTP connection is closed after completion of the request.
MaxRedirectAttemptsLimits the number of redirects that are followed in a request.
OtherHeadersOther headers as determined by the user (optional).
ProxyAuthorizationThe authorization string to be sent to the proxy server.
ProxyAuthSchemeThe authorization scheme to be used for the proxy.
ProxyPasswordA password if authentication is to be used for the proxy.
ProxyPortPort for the proxy server (default 80).
ProxyServerName or IP address of a proxy server (optional).
ProxyUserA user name if authentication is to be used for the proxy.
TransferredDataLimitThe maximum number of incoming bytes to be stored by the component.
TransferredHeadersThe full set of headers as received from the server.
UseChunkedEncodingEnables or Disables HTTP chunked encoding for transfers.
ChunkSizeSpecifies the chunk size in bytes when using chunked encoding.
UserAgentInformation about the user agent (browser).
KerberosSPNThe Service Principal Name for the Kerberos Domain Controller.
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the component whether or not to automatically detect and use firewall system settings, if available.
FirewallHostName or IP address of firewall (optional).
FirewallPasswordPassword to be used if authentication is to be used when connecting through the firewall.
FirewallPortThe TCP port for the FirewallHost;.
FirewallTypeDetermines the type of firewall to connect through.
FirewallUserA user name if authentication is to be used connecting through a firewall.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
LingerWhen set to True, connections are terminated gracefully.
LingerTimeTime in seconds to have the connection linger.
LocalHostThe name of the local host through which connections are initiated or accepted.
LocalPortThe TCP port in the local host where the component binds.
MaxLineLengthThe maximum amount of data to accumulate when no EOL is found.
MaxTransferRateThe transfer rate limit in bytes per second.
RecordLengthThe length of received data records.
TCPKeepAliveDetermines whether or not the keep alive socket option is enabled.
UseIPv6Whether to use IPv6.
TcpNoDelayWhether or not to delay when sending packets.
ReuseSSLSessionDetermines if the SSL session is reused.
SSLCipherStrengthThe minimum cipher strength used for bulk encryption.
SSLEnabledProtocolsUsed to enable/disable the supported security protocols.
SSLProviderThe name of the security provider to use.
SSLSecurityFlagsFlags that control certificate verification.
OpenSSLCADirThe path to a directory containing CA certificates.
OpenSSLCAFileName of the file containing the list of CA's trusted by your application.
OpenSSLCipherListA string that controls the ciphers to be used by SSL.
OpenSSLPrngSeedDataThe data to seed the pseudo random number generator (PRNG).
AbsoluteTimeoutDetermines whether timeouts are inactivity timeouts or absolute timeouts.
FirewallDataUsed to send extra data to the firewall.
InBufferSizeThe size in bytes of the incoming queue of the socket.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
CodePageThe system code page used for Unicode to Multibyte translations.

 
 
Copyright (c) 2017 /n software inc. - All rights reserved.
Build 1.0.6240.0