Vault - update UserDefinedProperties in files using API / C#

Vault - update UserDefinedProperties in files using API / C#

r_rybinskiA9RRF
Participant Participant
1,662 Views
3 Replies
Message 1 of 4

Vault - update UserDefinedProperties in files using API / C#

r_rybinskiA9RRF
Participant
Participant

Hello Friends,

 

I come here with a problem I have been trying to solve for several days now. I want to automate filling UserDefinedProperties created for PDF files in Vault. I have a pretty big library with PDFs and CSV file with attributes that I want to inject into UDP in Vault. 

 

I already managed to connect to Vault using C#, access folder with PDFs and list all filenames and Properties with values but I don't know how can I update them with my attributes. I already went through VaultSDK.chm but it didn't help much.

 

If you could share example code in C# / VB it would help me a lot. 

0 Likes
Accepted solutions (1)
1,663 Views
3 Replies
Replies (3)
Message 2 of 4

Gabriel_Watson
Mentor
Mentor
Accepted solution
Message 3 of 4

jaapflonk
Participant
Participant

This is how i do it:

 

First i get a download ticket (you can alo use DocumentService.CheckoutFile

 

ByteArray ticket = documentService.GetDownloadTicketsByFileIds(new long[] { selectedFile.Id }).First();

 

 

 

Use the ticket to find the properties 

 

            CtntSrcPropDef[] fileProps = Globals.Connection.WebServiceManager.FilestoreService.GetContentSourcePropertyDefinitions(
                ticket.Bytes, true);

 

 

Then i create PropWriteRequests

 

PropWriteRequests propWriteRequests = new PropWriteRequests();
            List<PropWriteReq> requests = new List<PropWriteReq>() 
            { 
                new PropWriteReq()
                {
                    CanCreate = true,
                    Moniker = "VltCategory!{D5CDD505-2E9C-101B-9397-08002B2CF9AE}!nvarchar", // Moniker van VltCategory property
                    Val = selectedFile.Cat.CatName
                }
            };
            
            propWriteRequests.Requests = requests.ToArray();

 

 

 

Then i use CopyFile and include the propWriteRequest

 

PropWriteResults propWriteResults = new PropWriteResults();
            byte[] uploadTicket = filestoreService.CopyFile(ticket.Bytes, extension, true, propWriteRequests, out propWriteResults);

 

 

And now use DocumentService.AddUploadedFile to upload the file with the new properties.

If you used CheckOut on step one can just check the file in.

 

            File newFile = documentService.AddUploadedFile(targetFolderId, tempFileName, "Temporary copy design for Flatten command", selectedFile.ModDate, null, bom, selectedFile.FileClass, false, uploadByteArray);

 

 

 

 

More information can be found here: 

https://justonesandzeros.typepad.com/blog/2015/02/another-way-to-update-properties.html

 

Good luck

 

Message 4 of 4

r_rybinskiA9RRF
Participant
Participant
Thank you Gabriel, I found solution in one of your link.