I tried this version and it seems to work.
Step 1. Checkout file:
ByteArray downloadTicket;
Autodesk.Connectivity.WebServices.File downloadResult = _connection.WebServiceManager.DocumentService.CheckoutFile(
file.Id,
CheckoutFileOptions.Master,
Environment.MachineName,
path,
comment,
out downloadTicket
);
Step 2: Read new file contents into ByteArray:
// Get contents of file
using (var stream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read))
{
byte[] bytes = new byte[stream.Length];
int numBytesToRead = (int)stream.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
int n = stream.Read(bytes, numBytesRead, numBytesToRead);
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
stream.Close();
// Upload file to Vault
checkinByteArray = UploadFileResource(sourceFilePath, bytes);
}
Step 3: Upload file to Vault. This method I found on this forum.
private ByteArray UploadFileResource(string filename, byte[] fileContents)
{ _connection.WebServiceManager.FilestoreService.FileTransferHeaderValue = new FileTransferHeader();
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.Identity = Guid.NewGuid();
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.Extension = Path.GetExtension(filename);
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.Vault = _connection.WebServiceManager.WebServiceCredentials.VaultName;
ByteArray uploadTicket = new ByteArray();
int bytesTotal = (fileContents != null ? fileContents.Length : 0);
int bytesTransferred = 0;
do
{
int bufferSize = (bytesTotal - bytesTransferred) % maxTransferSize;
byte[] buffer = null;
if (bufferSize == bytesTotal)
{
buffer = fileContents;
}
else
{
buffer = new byte[bufferSize];
Array.Copy(fileContents, (long)bytesTransferred, buffer, 0, (long)bufferSize);
}
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.Compression = Compression.None;
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.IsComplete = (bytesTransferred + bufferSize) == bytesTotal ? true : false;
_connection.WebServiceManager.FilestoreService.FileTransferHeaderValue.UncompressedSize = bufferSize;
using (var fileContentsStream = new MemoryStream(fileContents))
uploadTicket.Bytes = _connection.WebServiceManager.FilestoreService.UploadFilePart(fileContentsStream);
bytesTransferred += bufferSize;
} while (bytesTransferred < bytesTotal);
return uploadTicket;
}
}
Step 4: Check in file
Autodesk.Connectivity.WebServices.File checkInResult = _connection.WebServiceManager.DocumentService.CheckinUploadedFile(
file.MasterId,
comment,
false,
DateTime.UtcNow,
fileAssociations,
null,
false,
null,
file.FileClass,
file.Hidden,
checkinByteArray);