By Wayne Brill
The topic “ How To Acquire Files” in the the Vault 2017 SDK has a section titled: “File Transfer - Doing it the Hard Way”. In that section there are a couple of links to C# and VB examples. The DownloadFile function in these examples will not work with Vault 2017 due to the change to the DownloadFilePart method. It has changed in 2017 and doesn't return a byte array anymore, but a stream instead.
Here is an update to the DownloadFile function that works with the 2017 API.
private static void DownloadFile(vltutil.WebServiceManager mgr, out byte[] fileContents,
vltobj.ByteArray downloadTicket, bool allowSync)
{
mgr.FilestoreService.CompressionHeaderValue = new vltobj.CompressionHeader();
mgr.FilestoreService.CompressionHeaderValue.Supported = vltobj.Compression.None;
mgr.FilestoreService.FileTransferHeaderValue = new vltobj.FileTransferHeader();
mgr.FilestoreService.FileTransferHeaderValue = null;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
long bytesRead = 0;
while (mgr.FilestoreService.FileTransferHeaderValue == null ||
!mgr.FilestoreService.FileTransferHeaderValue.IsComplete)
{
using (Stream filePart = mgr.FilestoreService.DownloadFilePart(downloadTicket.Bytes,
bytesRead, bytesRead + MAX_FILE_PART_SIZE - 1, allowSync))
{
int chunkSize = (mgr.FilestoreService.FileTransferHeaderValue != null) ?
mgr.FilestoreService.FileTransferHeaderValue.UncompressedSize : 0;
if (chunkSize > 0)
{
filePart.CopyTo(stream);
bytesRead += chunkSize;
}
}
}
fileContents = new byte[bytesRead];
if (bytesRead > 0)
{
stream.Seek(0, System.IO.SeekOrigin.Begin);
stream.Read(fileContents, 0, (int)bytesRead);
}
}
}
vltobj.ByteArray downloadTicket, bool allowSync)
{
mgr.FilestoreService.CompressionHeaderValue = new vltobj.CompressionHeader();
mgr.FilestoreService.CompressionHeaderValue.Supported = vltobj.Compression.None;
mgr.FilestoreService.FileTransferHeaderValue = new vltobj.FileTransferHeader();
mgr.FilestoreService.FileTransferHeaderValue = null;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
long bytesRead = 0;
while (mgr.FilestoreService.FileTransferHeaderValue == null ||
!mgr.FilestoreService.FileTransferHeaderValue.IsComplete)
{
using (Stream filePart = mgr.FilestoreService.DownloadFilePart(downloadTicket.Bytes,
bytesRead, bytesRead + MAX_FILE_PART_SIZE - 1, allowSync))
{
int chunkSize = (mgr.FilestoreService.FileTransferHeaderValue != null) ?
mgr.FilestoreService.FileTransferHeaderValue.UncompressedSize : 0;
if (chunkSize > 0)
{
filePart.CopyTo(stream);
bytesRead += chunkSize;
}
}
}
fileContents = new byte[bytesRead];
if (bytesRead > 0)
{
stream.Seek(0, System.IO.SeekOrigin.Begin);
stream.Read(fileContents, 0, (int)bytesRead);
}
}
}