How can I find the item, when I only know the file ID of the file in the project folder (for example by
CheckinFileEvents_GetRestrictions, where the masterid of a file is given)
I suspect an item has only 1 primary linked file (is this true?) and did it by the following code (Vault 2012):
long nItemId = 0;
long nFileMasterId = 2241; // for example
Autodesk.Connectivity.WebServices.File allFiles = m_serviceManager.DocumentService.GetFilesByMasterI
if (allFiles != null && allFiles.Length > 0)
IEnumerable<long> fileIds = from file in allFiles select file.Id;
long fileIdArray = fileIds.ToArray();
Item itemsAll = m_serviceManager.ItemService.GetAllLatestItems();
if (itemsAll != null && itemsAll.Length > 0)
IEnumerable<long> ids = from item in itemsAll select item.Id;
long itemIdArray = ids.ToArray();
ItemFileAssoc associations = m_serviceManager.ItemService.GetItemFileAssociatio
if (associations != null && associations.Length > 0)
bool bFound = false;
foreach (ItemFileAssoc assoc in associations)
if (bFound == false)
foreach (long id in fileIdArray)
if (id == assoc.CldFileId)
nItemId = assoc.ParItemId;
bFound = true;
Is this the only one possibility or is there a better way?
By the way, in my test, the linked primary file has not the newest version as you can see in the attachment.
is this a fact?
Have I to resolve the link and reassign to the newest version manually?
How to do this by Api?
Yes, there is an easier way. Starting with the file master ID, you should be able to get what you want in 2 API calls.
1. Call GetLatestFileByMasterId to get a File object.
2. Call GetItemsByFileIdAndLinkTypeOptions passing in the ID of the File. Even if the item was created from an older file version, this function will still find the related items.
To answer your other question: Yes, it's true that an item will have no more than one primary link to a file. But you don't need to use that fact in this case.
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!