By Barbara Han
Issue
Is there a way to remove an associated file from a vault item using the web services API in .net. I have looked through the API and have not been able to figure this out.
Solution
If you want to remove the file link to the item, then EditItem (or PromoteFiles or AddItemRevision) -> UpdateAndCommitItem is the correct way to do that.
The UpdateAndCommitItem function has many arguments. If you want to get the original file association links for the item, you can refer to this post: Remove, Add or Modify Custom Item Properties in Vault.
If you want to remove all file association links from the item, but keep the some properties, then setting those link parameters of the UpdateAndCommitItem to zero or null, and passing the PropInst array in will do that. For example:
Item editItem = m_serviceManager.ItemService.EditItem(m_selectedItem.RevId);
PropDef[] props = m_serviceManager.ItemService.GetAllItemPropertyDefinitions();
System.Collections.ArrayList userProperties = new System.Collections.ArrayList();
foreach (PropDef propDef in props)
{
if (propDef.DispName == "Type")
{
continue;
}
userProperties.Add(propDef.Id);
}
PropInst[] propValues = m_serviceManager.ItemService.GetItemProperties(
new long[] { editItem.Id }, (long[])userProperties.ToArray(typeof(long)));
m_serviceManager.ItemService.UpdateAndCommitItem(editItem,0,false,null,null,
null, null,propValues, 7);