<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Programmatically checkout, overwrite and check in file in Vault Customization Forum</title>
    <link>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9510114#M4036</link>
    <description>&lt;P&gt;I'm writing an API in C# .NET. What I need to do is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Checkout file&lt;/P&gt;&lt;P&gt;2. Overwrite it with local file&lt;/P&gt;&lt;P&gt;3. Check the file back in with a comment and incremented version number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried different ways and nothing works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What methods should I use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Acquire file and&amp;nbsp;CheckoutFile.&amp;nbsp; This part works just fine.&lt;BR /&gt;2. I think I can overwrite the file using .NET&amp;nbsp;&lt;SPAN&gt;File.Copy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. I'm lost. I tried CheckInFile and get 8000 error, I tried&amp;nbsp;CheckinUploadedFile with checkout ticket and with new ticket.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone have any suggestions?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 14:40:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-05-12T14:40:59Z</dc:date>
    <item>
      <title>Programmatically checkout, overwrite and check in file</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9510114#M4036</link>
      <description>&lt;P&gt;I'm writing an API in C# .NET. What I need to do is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Checkout file&lt;/P&gt;&lt;P&gt;2. Overwrite it with local file&lt;/P&gt;&lt;P&gt;3. Check the file back in with a comment and incremented version number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried different ways and nothing works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What methods should I use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Acquire file and&amp;nbsp;CheckoutFile.&amp;nbsp; This part works just fine.&lt;BR /&gt;2. I think I can overwrite the file using .NET&amp;nbsp;&lt;SPAN&gt;File.Copy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. I'm lost. I tried CheckInFile and get 8000 error, I tried&amp;nbsp;CheckinUploadedFile with checkout ticket and with new ticket.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone have any suggestions?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 14:40:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9510114#M4036</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-05-12T14:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically checkout, overwrite and check in file</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9512159#M4037</link>
      <description>&lt;P&gt;This code snippet should share all you need, except the override of the downloaded file (Step 2.)&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;VDF.Vault.Settings.AcquireFilesSettings aqSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection)
                        {
                            DefaultAcquisitionOption = VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Checkout
                        };
                        vdfFile = new VDF.Vault.Currency.Entities.FileIteration(connection, wsFile);
                        aqSettings.AddEntityToAcquire(vdfFile);
                        var results = connection.FileManager.AcquireFiles(aqSettings);
                        try
                        {
                            mUploadedFile = connection.FileManager.CheckinFile(results.FileResults.First().File, "Created by Job Processor", false, null, null, false, null, ACW.FileClassification.DesignRepresentation, false, vdfPath);
                            mExpFile = mUploadedFile;
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Job could not update existing export file " + vdfFile + "Exception: ", ex);
                        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;You see the context here is a custom job, but this doesn't matter. If you need more insights on the step required before goto the full source:&amp;nbsp;&lt;A href="https://github.com/koechlm/Vault-Sample---InventorExportAnySampleJob" target="_blank"&gt;https://github.com/koechlm/Vault-Sample---InventorExportAnySampleJob&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Need to know: this code applies to non-CAD files only. CAD files may have BOM information that needs to be updated or at least kept for the new file version.&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 08:23:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9512159#M4037</guid>
      <dc:creator>Markus.Koechl</dc:creator>
      <dc:date>2020-05-13T08:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically checkout, overwrite and check in file</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9513018#M4038</link>
      <description>&lt;P&gt;I tried this version and it seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 1. Checkout file:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ByteArray downloadTicket;

Autodesk.Connectivity.WebServices.File downloadResult = _connection.WebServiceManager.DocumentService.CheckoutFile(
                       file.Id,
                       CheckoutFileOptions.Master,
                       Environment.MachineName,
                       path,
                       comment,
                       out downloadTicket
                    );&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 2:&amp;nbsp; Read new file contents into ByteArray:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;//  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 &amp;gt; 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);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 3: Upload file to Vault. This method I found on this forum.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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 &amp;lt; bytesTotal);

                return uploadTicket;
            }                    
}        &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Step 4:&amp;nbsp; Check in file&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt; Autodesk.Connectivity.WebServices.File checkInResult = _connection.WebServiceManager.DocumentService.CheckinUploadedFile(
                   file.MasterId,
                   comment,
                   false,
                   DateTime.UtcNow,
                   fileAssociations,
                   null,
                   false,
                   null,
                   file.FileClass,
                   file.Hidden,
                   checkinByteArray);&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 May 2020 13:58:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/programmatically-checkout-overwrite-and-check-in-file/m-p/9513018#M4038</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-05-13T13:58:49Z</dc:date>
    </item>
  </channel>
</rss>

