Deleting links of files

Deleting links of files

Saulius.Juskevicius
Participant Participant
1,341 Views
7 Replies
Message 1 of 8

Deleting links of files

Saulius.Juskevicius
Participant
Participant

Hello,
I'm having problems deleting links to files in Vault 2019, using C#. 
I want to delete Selected link, but  I get original file's ID and other properties. I've tried using DocumentService methods to get links but methods return null values.
Any help getting link ID would be appreciated.

0 Likes
Accepted solutions (1)
1,342 Views
7 Replies
Replies (7)
Message 2 of 8

psaarloos
Collaborator
Collaborator

Hi,

 

You should be able to get the Link ID's by using the GetLinksByParentIds function in the DocumentService. Once you have the ID's you should be able to remove them by using the DeleteLinks method of the DocumentService.

 

Hope it helps..

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 3 of 8

Saulius.Juskevicius
Participant
Participant

Thanks for reply,

But GetLinksByParentIds method works by giving folderID and it finds all links inside that folder, but how do I get link's location, and not originals files location then? 

This is how I used this method.

 

Lnk[] links= _connection.WebServiceManager.DocumentService.GetLinksByParentIds(new long[] { selectedFile.Id }, new string[] { "FILE" });

 

0 Likes
Message 4 of 8

psaarloos
Collaborator
Collaborator

Hi,

 

In that case you might want to use GetLinksByTargetEntityIds and pass in the file Id. You'll get a link collection back which tell you what the parent entity class id and parent id is. See image below.

 

Debug.png

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 5 of 8

Saulius.Juskevicius
Participant
Participant

I've tried this method but it returns null. Here's code how I get the selected file. And then I create FileIteration object.

 foreach (ISelection item in e.Context.CurrentSelectionSet)
                {
                    ISelection selection = item;
                    File selectedFile = null;
if (selection.TypeId == SelectionTypeId.File) { selectedFile = mDocSvc.GetLatestFileByMasterId(selection.Id); }
}

Capture.PNG

0 Likes
Message 6 of 8

psaarloos
Collaborator
Collaborator
Accepted solution

Hi,

 

I think that's because you're checking out the file before you call this method. When checking out a file a new version is already created. The GetLinksByTargetEntityIds method seems to need the id of the latest version of a file. Try this:

 

ACW.File latest = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(selectedFile.EntityMasterId);
ACW.Lnk[] links = connection.WebServiceManager.DocumentService.GetLinksByTargetEntityIds(new long[] { latest.Id });

 

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 7 of 8

Saulius.Juskevicius
Participant
Participant

Yeah, the problem was that I checked the file out before attempting using the methods. 
Now I can delete links but how could I delete only the specific one because now I delete all links for file.

0 Likes
Message 8 of 8

psaarloos
Collaborator
Collaborator

Hi,

 

You would need to loop through the Lnk collection and look at the Lnk properties te determine if that's the link you are looking for. You might need to call some other methods to parse in the FLDR id (ParentId property of the Lnk) for example to find out which folder the link is refering to.

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes