Box Component
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
nsoftware.InCloudStorage.Box
Remarks
The Box component 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 component 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-VrXSsxEZu5p0pclxGdKKQAssign 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:
- ResourceDeleted
- ResourceETag
- ResourceHash (not applicable to folders)
- ResourceId
- ResourceMarker
- ResourceName
- ResourceRevision
- ResourceType
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. The file will be downloaded to the stream specified (if any) by SetDownloadStream. If a stream is not specified and LocalFile is set the file will be saved to the specified location. If a stream is not specified and 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 component 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 component 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 component offers advanced functionality beyond simple uploads and downloads. For instance:
- Encrypt and decrypt files using EncryptionAlgorithm and EncryptionPassword.
- CreateMetadata, UpdateMetadata, and DeleteMetadata allow creation and management of resource metadata.
- ShareResource creates shareable links to content.
- Search can be used to search for matching content.
- Revisions are supported through ListRevisions and PromoteRevision.
- Undelete files with ListDeletedResources, and RestoreResource.
- GetAccountInfo provides usage and account information.
- GetPreviewLink and GetThumbnail retrieve preview information for files.
- And more!
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
Account | This property defines details about the account. |
Authorization | OAuth 2.0 Authorization Token. |
EncryptionAlgorithm | The encryption algorithm. |
EncryptionPassword | The encryption password. |
Firewall | A set of properties related to firewall access. |
LocalFile | The location of the local file. |
LocalHost | The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
MetadataFields | A collection of metadata fields associated with the resource. |
Overwrite | Whether to overwrite the local or remote file. |
Proxy | A set of properties related to proxy access. |
QueryParams | Addtional query parameters to be included in the request. |
ResourceCount | The number of files and folders. |
ResourceCreatedBy | The email of the creator of the resource. |
ResourceCreatedDate | The date on which the resource was created. |
ResourceData | Holds the file data after downloading or sets the file data before uploading or updating. |
ResourceDeleted | Whether the resource is deleted. |
ResourceDeletedDate | The date on which the resource was deleted. |
ResourceDescription | A short description of the file or folder. |
ResourceETag | The ETag of the resource. |
ResourceHash | The SHA1 hash of the file. |
ResourceId | The unique identifier of the resource. |
ResourceIndex | Selects the file or folder. |
ResourceMarker | A marker when list results are paged. |
ResourceModifiedBy | The email of the user who last modified the resource. |
ResourceModifiedDate | The date on which the resource was modified. |
ResourceName | The name of the resource. |
ResourceOwner | The email of the resource owner. |
ResourceParentId | The Id of the parent resource. |
ResourcePurgedDate | The date on which the resource will be permanently deleted. |
ResourceRevision | The revision of the file. |
ResourceSize | The size of the resource in bytes. |
ResourceSyncState | The sync state of the folder. |
ResourceTags | A comma separate list of tags. |
ResourceType | Indicates whether the current entry is a folder or a file. |
SearchMarker | A marker when searches are paged. |
SharedResourceInfo | Defines information about the shared resource. |
SSLAcceptServerCert | Instructs the component to unconditionally accept the server certificate that matches the supplied certificate. |
SSLCert | The certificate to be used during SSL negotiation. |
SSLServerCert | The server certificate for the last established connection. |
StartByte | The byte offset from which to start the upload or download. |
ThumbnailFormat | The thumbnail format. |
ThumbnailSize | The size of the thumbnail in pixels. |
Timeout | A timeout for the component. |
TotalSpace | The total allowed space in bytes. |
UsedSpace | The amount of space used in bytes. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
AddQueryParam | Adds a query parameter to the QueryParams properties. |
Config | Sets or retrieves a configuration setting . |
CopyResource | Copies the specified resource to a new location. |
CreateFolder | Creates a folder with the specified name. |
CreateMetadata | Creates metadata for a file. |
DeleteMetadata | Deletes all metadata for a file. |
DeleteResource | Deletes the specified resource. |
DownloadFile | Downloads a file. |
GetAccountInfo | Retrieves information about the current user account. |
GetMetadata | Retrieves metadata for the file. |
GetPreviewLink | Gets a link that may be used to preview the resource. |
GetResourceInfo | Retrieves information about the specified resource. |
GetSharedResourceInfo | Gets information about a shared resource. |
GetThumbnail | Retrieves a thumbnail image of the current resource. |
Interrupt | Interrupt the current method. |
ListDeletedResources | Lists deleted resources. |
ListResources | Lists the resources in the specified folder. |
ListRevisions | Lists revisions for a file. |
LockFile | Locks the specified file. |
PromoteRevision | Promotes a specific revision of a file to the current version. |
RestoreResource | Restores a deleted resource. |
Search | This method searches resources for the specified query. |
SetDownloadStream | Sets the stream to which the downloaded file will be written. |
SetUploadStream | Sets the stream from which data is read when uploading. |
ShareResource | Shares the specified file or folder. |
UnlockFile | Unlocks the specified file. |
UnshareResource | Stops sharing a resource. |
UpdateMetadata | Updates metadata fields for a file. |
UpdateResource | Updates the file or folder. |
UploadFile | Uploads a file. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
EndTransfer | Fired when a document finishes transferring. |
Error | Information about errors during data delivery. |
ResourceList | Fired for each resource listed. |
SSLServerAuthentication | Fired after the server presents its certificate to the client. |
SSLStatus | Shows the progress of the secure connection. |
StartTransfer | Fired when a document starts transferring (after the headers). |
Transfer | Fired while a document transfers (delivers document). |
Configuration Settings
The following is a list of configuration settings for the component with short descriptions. Click on the links for further details.
DownloadTempFile | The temporary file used when downloading encrypted data. |
IncludeFileHash | Whether to include the SHA1 hash when uploading a file. |
MaxResults | The maximum number of results to return when searching or listing resources. |
ResourceClientCreatedDate | A client assigned creation date. |
ResourceClientModifiedDate | A client assigned modified date. |
RetryAfter | The number of seconds after which to retry the request. |
TempPath | The path to the directory where temporary files are created. |
EncryptionIV | The initialization vector to be used for encryption/decryption. |
EncryptionKey | The key to use during encryption/decryption. |
XPath | Provides a way to point to a specific element in the returned XML response. |
XElement | The name of the current element. |
XParent | The parent of the current element. |
XSubTree | A snapshot of the current element in the document. |
XText | The text of the current element. |
XChildCount | The 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. |
AcceptEncoding | Used to tell the server which types of content encodings the client supports. |
AllowHTTPCompression | This property enables HTTP compression for receiving data. |
AllowIdenticalRedirectURL | Allow redirects to the same URL. |
Append | Whether to append data to LocalFile. |
Authorization | The Authorization string to be sent to the server. |
BytesTransferred | Contains the number of bytes transferred in the response data. |
EncodeURL | If set to true the URL will be encoded by the component. |
FollowRedirects | Determines what happens when the server issues a redirect. |
GetOn302Redirect | If set to true the component will perform a GET on the new location. |
HTTPVersion | The version of HTTP used by the component. |
IfModifiedSince | A date determining the maximum age of the desired document. |
KeepAlive | Determines whether the HTTP connection is closed after completion of the request. |
MaxRedirectAttempts | Limits the number of redirects that are followed in a request. |
OtherHeaders | Other headers as determined by the user (optional). |
ProxyAuthorization | The authorization string to be sent to the proxy server. |
ProxyAuthScheme | The authorization scheme to be used for the proxy. |
ProxyPassword | A password if authentication is to be used for the proxy. |
ProxyPort | Port for the proxy server (default 80). |
ProxyServer | Name or IP address of a proxy server (optional). |
ProxyUser | A user name if authentication is to be used for the proxy. |
TransferredDataLimit | The maximum number of incoming bytes to be stored by the component. |
TransferredHeaders | The full set of headers as received from the server. |
UseChunkedEncoding | Enables or Disables HTTP chunked encoding for transfers. |
ChunkSize | Specifies the chunk size in bytes when using chunked encoding. |
UserAgent | Information about the user agent (browser). |
KerberosSPN | The Service Principal Name for the Kerberos Domain Controller. |
ConnectionTimeout | Sets a separate timeout value for establishing a connection. |
FirewallAutoDetect | Tells the component whether or not to automatically detect and use firewall system settings, if available. |
FirewallHost | Name or IP address of firewall (optional). |
FirewallPassword | Password to be used if authentication is to be used when connecting through the firewall. |
FirewallPort | The TCP port for the FirewallHost;. |
FirewallType | Determines the type of firewall to connect through. |
FirewallUser | A user name if authentication is to be used connecting through a firewall. |
KeepAliveTime | The inactivity time in milliseconds before a TCP keep-alive packet is sent. |
KeepAliveInterval | The retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received. |
Linger | When set to True, connections are terminated gracefully. |
LingerTime | Time in seconds to have the connection linger. |
LocalHost | The name of the local host through which connections are initiated or accepted. |
LocalPort | The TCP port in the local host where the component binds. |
MaxLineLength | The maximum amount of data to accumulate when no EOL is found. |
MaxTransferRate | The transfer rate limit in bytes per second. |
RecordLength | The length of received data records. |
TCPKeepAlive | Determines whether or not the keep alive socket option is enabled. |
UseIPv6 | Whether to use IPv6. |
TcpNoDelay | Whether or not to delay when sending packets. |
ReuseSSLSession | Determines if the SSL session is reused. |
SSLCipherStrength | The minimum cipher strength used for bulk encryption. |
SSLEnabledProtocols | Used to enable/disable the supported security protocols. |
SSLProvider | The name of the security provider to use. |
SSLSecurityFlags | Flags that control certificate verification. |
OpenSSLCADir | The path to a directory containing CA certificates. |
OpenSSLCAFile | Name of the file containing the list of CA's trusted by your application. |
OpenSSLCipherList | A string that controls the ciphers to be used by SSL. |
OpenSSLPrngSeedData | The data to seed the pseudo random number generator (PRNG). |
AbsoluteTimeout | Determines whether timeouts are inactivity timeouts or absolute timeouts. |
FirewallData | Used to send extra data to the firewall. |
InBufferSize | The size in bytes of the incoming queue of the socket. |
OutBufferSize | The size in bytes of the outgoing queue of the socket. |
CodePage | The system code page used for Unicode to Multibyte translations. |