Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
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.
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<ItemFileAssoc>();
var primary = existingLinks.FirstOrDefault(a => a.Typ == ItemFileLnkTyp.Primary);
var isPrimarySub = existingLinks.Any(a => a.Typ == ItemFileLnkTyp.PrimarySub);
var secondaries = existingLinks
.Where(a => a.Typ == ItemFileLnkTyp.Secondary)
.Select(a => a.CldFileId)
.ToList();
var standardComponents = existingLinks
.Where(a => a.Typ == ItemFileLnkTyp.StandardComponent)
.Select(a => a.CldFileId)
.ToList();
var secondarySubs = existingLinks
.Where(a => a.Typ == ItemFileLnkTyp.SecondarySub)
.Select(a => a.CldFileId)
.ToList();
var tertiaries = existingLinks
.Where(a => a.Typ == ItemFileLnkTyp.Tertiary)
.Select(a => 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 });
}
If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".
If this post solved your problem, please mark it as "Solution.".
Solved! Go to Solution.