<?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 Re: Assign file to existing Item in Vault Customization Forum</title>
    <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13771717#M12976</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/33301"&gt;@Markus.Koechl&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really have no idea why this is happening. I cannot assign a file to an already existing item that already has a primary file. I would like to add to the item a file whose part number is the same as the item name. When I do this from the application level or using "Assign/Update item," everything works correctly, but when I try to assign it programmatically, the code executes properly without any errors, I can see that the item "TESTOWY_ITEM" was edited, but no new file was added as secondary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to add it this way, a new item with a strange name gets created. Most likely this happens because the vault does not allow adding two items with the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt; File file = FindFileBySearchCondidtions(vaultConnection, "PRO-000190406.ipt");
 long fileID = file.Id;

 if (fileID != 0)
 {
     Item item = vaultConnection.WebServiceManager.ItemService.GetLatestItemByItemNumber("TESTOWY_ITEM");
     if (item != null)
     {
         item = vaultConnection.WebServiceManager.ItemService.EditItems(new long[] { item.RevId }).FirstOrDefault();

         vaultConnection.WebServiceManager.ItemService.AddFilesToPromote(
             new long[] { fileID },
             ItemAssignAll.Default,
             false
         );

         DateTime timestamp;
         GetPromoteOrderResults promoteOrder = vaultConnection.WebServiceManager.ItemService.GetPromoteComponentOrder(out timestamp);

         vaultConnection.WebServiceManager.ItemService.PromoteComponents(timestamp, promoteOrder.PrimaryArray);

         ItemsAndFiles promoteResults = vaultConnection.WebServiceManager.ItemService.GetPromoteComponentsResults(timestamp);
         vaultConnection.WebServiceManager.ItemService.UpdateAndCommitItems(promoteResults.ItemRevArray);
     }
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mateusz_baczewski_1-1755507317538.png" style="width: 1373px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1562047i93A2E5D203E89CEB/image-dimensions/1373x60?v=v2" width="1373" height="60" role="button" title="mateusz_baczewski_1-1755507317538.png" alt="mateusz_baczewski_1-1755507317538.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Aug 2025 08:55:54 GMT</pubDate>
    <dc:creator>mateusz_baczewski</dc:creator>
    <dc:date>2025-08-18T08:55:54Z</dc:date>
    <item>
      <title>Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13765703#M12966</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following problem: I’m trying to attach a file to an existing item. The code below executes without errors, and I can see from the date and time that the item was edited, but the file I specified was not attached. What could be causing this issue? I should add that the file I want to attach does exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; if (gridFileId != 0)
 {
     File file1 = mVault.WebServiceManager.DocumentService.GetFileById(gridFileId);
     Item item = mVault.WebServiceManager.ItemService.GetLatestItemByItemNumber("SIATKA N6");

     if (item != null)
     {
         var filter = ItemFileLnkTypOpt.Primary |
                      ItemFileLnkTypOpt.PrimarySub |
                      ItemFileLnkTypOpt.Secondary |
                      ItemFileLnkTypOpt.SecondarySub |
                      ItemFileLnkTypOpt.StandardComponent |
                      ItemFileLnkTypOpt.Tertiary;


         ItemFileAssoc[] assocByItem = mVault.WebServiceManager.ItemService
             .GetItemFileAssociationsByItemIds(new long[] { item.Id }, filter);

         var existingLinks = assocByItem?.ToList() ?? new List&amp;lt;ItemFileAssoc&amp;gt;();

         var primary = existingLinks.FirstOrDefault(a =&amp;gt; a.Typ == ItemFileLnkTyp.Primary);
         var isPrimarySub = existingLinks.Any(a =&amp;gt; a.Typ == ItemFileLnkTyp.PrimarySub);

         var secondaries = existingLinks
             .Where(a =&amp;gt; a.Typ == ItemFileLnkTyp.Secondary)
             .Select(a =&amp;gt; a.CldFileId)
             .ToList();

         var standardComponents = existingLinks
             .Where(a =&amp;gt; a.Typ == ItemFileLnkTyp.StandardComponent)
             .Select(a =&amp;gt; a.CldFileId)
             .ToList();

         var secondarySubs = existingLinks
             .Where(a =&amp;gt; a.Typ == ItemFileLnkTyp.SecondarySub)
             .Select(a =&amp;gt; a.CldFileId)
             .ToList();

         var tertiaries = existingLinks
             .Where(a =&amp;gt; a.Typ == ItemFileLnkTyp.Tertiary)
             .Select(a =&amp;gt; a.CldFileId)
             .ToList();

         if (!secondaries.Contains(gridFileId))
         {
             secondaries.Add(gridFileId);
         }

         long primaryFileId = primary?.CldFileId ?? 0;

         var editItem = mVault.WebServiceManager.ItemService.EditItems(new long[] { item.RevId }).FirstOrDefault();

         var updatedItem = mVault.WebServiceManager.ItemService.UpdateItemFileAssociations(
             editItem.RevId,
             primaryFileId,
             isPrimarySub,
             secondaries.ToArray(),
             standardComponents.ToArray(),
             secondarySubs.ToArray(),
             tertiaries.ToArray()
         );


         mVault.WebServiceManager.ItemService.UpdateAndCommitItems(new Item[] { updatedItem });

     }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Aug 2025 12:50:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13765703#M12966</guid>
      <dc:creator>mateusz_baczewski</dc:creator>
      <dc:date>2025-08-13T12:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13766527#M12969</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16895876"&gt;@mateusz_baczewski&lt;/a&gt;, I understand you would like to assign your file as primary, correct? In this case, I suggest using the&amp;nbsp;&lt;/P&gt;
&lt;DIV id="i-header-content" class="i-header-content"&gt;
&lt;DIV class="i-page-title"&gt;
&lt;DIV class="i-page-title-text"&gt;PromoteComponents() method instead. For this approach, the target Item (existing) must have the Equivalence property assigned and filled; you can manually try the behavior settings before you do it programmatically.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 13 Aug 2025 22:09:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13766527#M12969</guid>
      <dc:creator>Markus.Koechl</dc:creator>
      <dc:date>2025-08-13T22:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13767215#M12970</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/33301"&gt;@Markus.Koechl&lt;/a&gt;, no i would like to assing secondary file to item.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 10:24:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13767215#M12970</guid>
      <dc:creator>mateusz_baczewski</dc:creator>
      <dc:date>2025-08-14T10:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13767400#M12971</link>
      <description>&lt;P&gt;Adding new files to an existing Item PromoteComponents() will automatically create a secondary link if a primary one exists. So, I'd prefer the same approach of leveraging a matching equivalence value for all link types. If your files to promote have documentation files, or design representation files (new in 2026 Update1) they will link (documentation) or attach (design representation) in the same process.&lt;/P&gt;
&lt;P&gt;Anyway, if you have good reasons to follow your approach, the code should share a working sample to update associations (the sample moves secondary links to the standard component link type)&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;                    Item item = mVault.ItemService.GetLatestItemByItemNumber("ISO 10788-2 - 60 x 40 x 4");
                    item = mVault.ItemService.EditItems(new long[] { item.RevId }).FirstOrDefault();
                    ItemFileAssoc itemPrimAssoc = mVault.ItemService.GetItemFileAssociationsByItemIds(new long[] { item.Id }, ItemFileLnkTypOpt.Primary).FirstOrDefault();
                    ItemFileAssoc[] itemSecAssocs = mVault.ItemService.GetItemFileAssociationsByItemIds(new long[] { item.Id }, ItemFileLnkTypOpt.Secondary);
                    ItemFileAssoc[] itemStdAssocs = mVault.ItemService.GetItemFileAssociationsByItemIds(new long[] { item.Id }, ItemFileLnkTypOpt.StandardComponent);
                    List&amp;lt;long&amp;gt; secFileIds = itemSecAssocs.Select(n =&amp;gt; n.CldFileId).ToList&amp;lt;long&amp;gt;();
                    List&amp;lt;long&amp;gt; stdFileIds = itemStdAssocs.Select(n =&amp;gt; n.CldFileId).ToList&amp;lt;long&amp;gt;();
                    stdFileIds.AddRange(secFileIds);
                    long[] empty = new long[0];
                    item = mVault.ItemService.UpdateItemFileAssociations(item.RevId, itemPrimAssoc.CldFileId, false, empty, stdFileIds.ToArray(), empty, empty);
                    mVault.ItemService.UpdateAndCommitItems(new Item[] { item });&lt;/LI-CODE&gt;
&lt;P&gt;I hope this helps; I did not step through in detail your code - but I guess there is a minor (nasty) mismatch in the transfer of existing to new Ids.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 12:27:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13767400#M12971</guid>
      <dc:creator>Markus.Koechl</dc:creator>
      <dc:date>2025-08-14T12:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13771717#M12976</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/33301"&gt;@Markus.Koechl&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really have no idea why this is happening. I cannot assign a file to an already existing item that already has a primary file. I would like to add to the item a file whose part number is the same as the item name. When I do this from the application level or using "Assign/Update item," everything works correctly, but when I try to assign it programmatically, the code executes properly without any errors, I can see that the item "TESTOWY_ITEM" was edited, but no new file was added as secondary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to add it this way, a new item with a strange name gets created. Most likely this happens because the vault does not allow adding two items with the same name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt; File file = FindFileBySearchCondidtions(vaultConnection, "PRO-000190406.ipt");
 long fileID = file.Id;

 if (fileID != 0)
 {
     Item item = vaultConnection.WebServiceManager.ItemService.GetLatestItemByItemNumber("TESTOWY_ITEM");
     if (item != null)
     {
         item = vaultConnection.WebServiceManager.ItemService.EditItems(new long[] { item.RevId }).FirstOrDefault();

         vaultConnection.WebServiceManager.ItemService.AddFilesToPromote(
             new long[] { fileID },
             ItemAssignAll.Default,
             false
         );

         DateTime timestamp;
         GetPromoteOrderResults promoteOrder = vaultConnection.WebServiceManager.ItemService.GetPromoteComponentOrder(out timestamp);

         vaultConnection.WebServiceManager.ItemService.PromoteComponents(timestamp, promoteOrder.PrimaryArray);

         ItemsAndFiles promoteResults = vaultConnection.WebServiceManager.ItemService.GetPromoteComponentsResults(timestamp);
         vaultConnection.WebServiceManager.ItemService.UpdateAndCommitItems(promoteResults.ItemRevArray);
     }
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mateusz_baczewski_1-1755507317538.png" style="width: 1373px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1562047i93A2E5D203E89CEB/image-dimensions/1373x60?v=v2" width="1373" height="60" role="button" title="mateusz_baczewski_1-1755507317538.png" alt="mateusz_baczewski_1-1755507317538.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Aug 2025 08:55:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13771717#M12976</guid>
      <dc:creator>mateusz_baczewski</dc:creator>
      <dc:date>2025-08-18T08:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13773250#M12977</link>
      <description>&lt;P&gt;Use the PromoteComponentLinks() method to assign secondary or documentation links. I added a sample to my collection:&amp;nbsp;&lt;A href="https://github.com/koechlm/Vault-API-Snippets-and-Samples/blob/master/Vault-API-C%23-Samples/Items/API-ConsoleApp-PromoteFileToItem/Program.cs" target="_blank" rel="noopener"&gt;Vault-API-C#-Samples/Items/API-ConsoleApp-PromoteFileToItem/Program.cs&lt;/A&gt;. The sample requires two components with matching part number values. You can run the code once to create both link types in one go, or skip adding the secondary file in the first run and add it in the subsequent execution.&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 06:30:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13773250#M12977</guid>
      <dc:creator>Markus.Koechl</dc:creator>
      <dc:date>2025-08-19T06:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Assign file to existing Item</title>
      <link>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13776990#M12980</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/33301"&gt;@Markus.Koechl&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fantastic, this is exactly what I needed! Everything is working perfectly now. Many thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2025 10:14:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vault-customization-forum/assign-file-to-existing-item/m-p/13776990#M12980</guid>
      <dc:creator>mateusz_baczewski</dc:creator>
      <dc:date>2025-08-21T10:14:24Z</dc:date>
    </item>
  </channel>
</rss>

