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

OneDrive Control

Properties   Methods   Events   Configuration Settings   Errors  

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

Syntax

OneDrive

Remarks

The OneDrive control provides a simple interface to working with Microsoft OneDrive. 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 OneDrive. Consult the OneDrive documentation for instructions on this process.

Authentication

Authentication is performed via OAuth 2.0. Use the OAuth control 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 OneDrive 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 drive at the specified path.

Calling this method without specifying ResourceParentId or ResourceParentPath will list all resources in the drive's root. To list resources of a specific folder set either ResourceParentId or ResourceParentPath prior to calling this method. When ResourceParentId is set, it takes precedence over ResourceParentPath.

When either ResourceParentId or ResourceParentPath, children of the specified parent folder will be listed. These two properties can be set before calling this method to navigate the drive. If both are specified ResourceParentId takes precedence. If both are unspecified the drive root is assumed.

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 ResourceMarker will be populated. Call ListResources again to retrieve the next page of results. Continue calling ListResources until ResourceMarker is empty string to retrieve all pages.


onedrive.ListResources();
for (int i = 0; i < onedrive.ResourceCount; i++)
{
  onedrive.ResourceIndex = i;
  Console.WriteLine(onedrive.ResourceName);
  Console.WriteLine(onedrive.ResourceSize);
  Console.WriteLine(onedrive.ResourceModifiedDate);
}

Downloading Files

The DownloadFile method downloads a specific file.

Any of the following properties may be set to specify the file to download:

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.


onedrive.ResourceId = fileId;
onedrive.LocalFile = "../MyFile.zip";
onedrive.DownloadFile();

Resuming Downloads

The control 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.


onedrive.ResourceId = fileId;
onedrive.LocalFile = downloadFile;
onedrive.DownloadFile();

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

//Get the size of the partially download file
onedrive.StartByte = new FileInfo(downloadFile).Length; 
onedrive.ResourceId = fileId;
onedrive.LocalFile = downloadFile;
onedrive.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 control 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.

onedrive.ResourceId = fileId;
onedrive.LocalFile = downloadFile;
onedrive.EncryptionPassword = "password";
onedrive.DownloadFile();

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

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

Uploading Files

LocalFile specifies the file to upload. The data to upload may also be set in ResourceData .

The FileTitle parameter of UploadFile specifies the name of the file to be written in the drive.

To upload a file in a specific folder set ResourceParentId or ResourceParentPath to indicate the parent folder. If both are specified ResourceParentId takes precedence. If both are unspecified the drive root is assumed.

To encrypt a file before uploading set EncryptionAlgorithm and EncryptionPassword.

The UploadFile method returns the Id of the resource which was uploaded.

Upload Notes

Microsoft OneDrive offers two ways to upload a file. For smaller files a simple upload option is provided to upload data in one request. This is the default option. For larger files uploads can be fragmented into multiple pieces, allowing resuming of uploads that may be interrupted.

Simple

By default the control uses the simple upload mechanism. Only files up to 100 MB can be uploaded using the default simple upload.


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

The following properties are applicable when calling UploadFile and UseResumableUpload if False (default - simple upload):

Resumable

To enable resumable uploads set UseResumableUpload to True. This is recommended for files larger than 10 MB. The control will automatically fragment the specified file into smaller pieces and upload each individually. FragmentSize may be set to specify the size of the fragment if desired. The default fragment size is 10 MB.

When UseResumableUpload is set to True and UploadFile is called a resumable upload session is started by the control. ResumeURL is populated with the URL identifying the session. This value may be needed for additional operations if the upload does not complete normally. Additionally StartByte is updated as necessary by the control to indicate the current offset in the file.

If the upload is interrupted for any reason the upload may be resumed. To resume an upload verify that ResumeURL and StartByte are populated. If the same instance of the control is used these should already be populated and no special action is needed. Call UploadFile again to resume the upload at the specified StartByte offset.

If a resumable upload is interrupted for any reason, AbortUpload may be called to cancel the upload. If the upload is not resumed after some time the upload session will expire. UploadExpDate may be checked to determine when the upload session expires.

GetUploadStatus may be used to check the status of a resumable upload. The FragmentComplete event fires after each fragment is uploaded to indicate overall progress.


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

//The transfer is interrupted and UploadFile() above fails. Later, resume the download.
//Using the same instance StartByte and ResumeURL are already populated 
//from the previous upload attempt
onedrive.UploadFile("MyFile.zip");

The following properties are applicable when calling UploadFile and UseResumableUpload if True:

Additional Functionality

The OneDrive component offers advanced functionality beyond simple uploads and downloads. For instance:

Property List


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

AuthorizationOAuth 2.0 Authorization Token.
CopyPercentDoneThe progress of the copy operation.
CopyStatusThe status of the copy operation.
DriveCountThe number of drives available to the user.
DriveDeletedSpaceThe space consumed by deleted files in bytes.
DriveIdThe unique id of the selected drive.
DriveIndexSelects a drive.
DriveOwnerIdThe Id of the drive owner.
DriveOwnerNameThe name of the drive owner.
DriveRemainingSpaceThe remaining unused space in bytes.
DriveStateThe state of the drive space.
DriveTotalSpaceThe total space of the drive in bytes.
DriveTypeThe type of drive.
DriveUsedSpaceThe used space in bytes.
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.
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.
ResourceChildrenThe number of immediate children in the selected folder.
ResourceCountThe number of files and folders.
ResourceCRC32HashThe CRC32 hash value.
ResourceCreatedDateThe date when the item was created.
ResourceDataHolds the file data after downloading or sets the file data before uploading or updating.
ResourceDeletedWhether the resource is deleted.
ResourceDescriptionA short description of the file or folder.
ResourceDownloadURLThe URL used to download the file contents.
ResourceETagThe ETag of the resource.
ResourceIdThe unique identifier of the resource.
ResourceIndexSelects the file or folder.
ResourceMarkerThe marker specifying the next set of results.
ResourceMIMETypeThe MIME type of the file.
ResourceModifiedDateThe date when the item was modified.
ResourceNameThe name of the resource.
ResourceParentIdThe Id of the parent resource.
ResourceParentPathThe path of the parent resource.
ResourcePathThe full path to the specified resource.
ResourceSHA1HashThe SHA-1 hash value.
ResourceSizeThe size of the resource in bytes.
ResourceTypeIndicates whether the current entry is a folder or a file.
ResourceWebURLThe URL to view the resource in a browser.
ResumeURLThe URL for the resumable upload.
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.
TimeoutA timeout for the component.
URLThe server URL.
UseResumableUploadWhether to use resumable uploads.

Method List


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

AbortUploadAborts the resumable upload session.
AddQueryParamAdds a query parameter to the QueryParams properties.
ConfigSets or retrieves a configuration setting .
CopyResourceCopies the specified resource.
CreateFolderCreates a new folder.
CreateLinkCreates a link for sharing the resource.
DeleteResourceDeletes the specified resource.
DownloadFileDownloads the specified file.
GetCopyInfoGets information about the copy operation.
GetDriveInfoGets information about the drive.
GetResourceInfoGets information about the resource.
GetUploadStatusGet the status of a resumable upload session.
InterruptInterrupt the current method.
ListChangesLists changes to the drive.
ListDrivesList drives available to the user.
ListResourcesList resources in the current folder.
MoveResourceMoves the specified resource to a new folder.
SearchThis method searches for resources matching the specified query.
UpdateResourceUpdates the resource.
UploadFileUploads a file.

Event List


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

DriveListFired for each drive when ListDrives is called.
EndTransferFired when a document finishes transferring.
ErrorInformation about errors during data delivery.
FragmentCompleteThis event fires after each fragment of a resumable upload is completed.
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 control with short descriptions. Click on the links for further details.

CopyStatusURLThe URL from which copy status info is obtained.
DownloadTempFileThe temporary file used when downloading encrypted data.
FragmentSizeThe fragment size.
MaxResultsThe maximum number of results to return when calling ListResources.
RenameIfExistsWhether to rename the uploaded file if it exists.
TempPathThe path to the directory where temporary files are created.
UploadExpDateThe expiration of the resumable upload session.
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