Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get property value from file in Vault

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
gert-leonvanlier
1128 Views, 7 Replies

Get property value from file in Vault

gert-leonvanlier
Collaborator
Collaborator

I am looking for a way to get the value from a specific property of a file I know that is in the Vault.

 

The following code is working. At the end I placed a comment on where the value of the property "Category Name" should be looked up in the file that was found.

 

Thanks in advance for any help.

 

public bool CheckFileExistsInVault(string vaultFileName)
{
	WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
	var userName = windowsIdentity.Name;
	var password = "";
	var serverName = "xx.x.xx.xx";
	var vaultName = "Vault";
	VDF.Vault.Results.LogInResult results = null;
	try
	{
		results = VDF.Vault.Library.ConnectionManager.LogIn(serverName, vaultName, userName, password, VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, null);
	}
	catch
	{
		return false;
	}

	if (!results.Success)
	{
		MessageBox.Show("Unable to login to the Vault.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
		return false;
	}

	VDF.Vault.Currency.Connections.Connection connection = results.Connection;
	VDF.Vault.Currency.Entities.Folder rootFolder = connection.FolderManager.RootFolder;
	VDF.Vault.Currency.Entities.FileIteration fileIteration = null;

	try
	{
		fileIteration = GetFileIteration(vaultFileName, connection);
	}
	catch
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		return false;
	}

	if (fileIteration == null)
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		return false;
	}
	else
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		
		//get value of property "Category Name" here

		return true;
	}

	return false;
}

 

0 Likes

Get property value from file in Vault

I am looking for a way to get the value from a specific property of a file I know that is in the Vault.

 

The following code is working. At the end I placed a comment on where the value of the property "Category Name" should be looked up in the file that was found.

 

Thanks in advance for any help.

 

public bool CheckFileExistsInVault(string vaultFileName)
{
	WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
	var userName = windowsIdentity.Name;
	var password = "";
	var serverName = "xx.x.xx.xx";
	var vaultName = "Vault";
	VDF.Vault.Results.LogInResult results = null;
	try
	{
		results = VDF.Vault.Library.ConnectionManager.LogIn(serverName, vaultName, userName, password, VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, null);
	}
	catch
	{
		return false;
	}

	if (!results.Success)
	{
		MessageBox.Show("Unable to login to the Vault.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
		return false;
	}

	VDF.Vault.Currency.Connections.Connection connection = results.Connection;
	VDF.Vault.Currency.Entities.Folder rootFolder = connection.FolderManager.RootFolder;
	VDF.Vault.Currency.Entities.FileIteration fileIteration = null;

	try
	{
		fileIteration = GetFileIteration(vaultFileName, connection);
	}
	catch
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		return false;
	}

	if (fileIteration == null)
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		return false;
	}
	else
	{
		VDF.Vault.Library.ConnectionManager.LogOut(connection);
		
		//get value of property "Category Name" here

		return true;
	}

	return false;
}

 

7 REPLIES 7
Message 2 of 8

Nick_Hall
Advocate
Advocate

Hi Gert

 

You won't be able to get the Category Name where you have indicated, because in the line above you are logging out of Vault

 

But at line 30, you can get the Category Name of the file using something like this

 

string[] filePaths = { vaultFileName };
File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
string categoryName = files[0].Cat.CatName;

 

Hope that helps

 

Nick

0 Likes

Hi Gert

 

You won't be able to get the Category Name where you have indicated, because in the line above you are logging out of Vault

 

But at line 30, you can get the Category Name of the file using something like this

 

string[] filePaths = { vaultFileName };
File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
string categoryName = files[0].Cat.CatName;

 

Hope that helps

 

Nick

Message 3 of 8

gert-leonvanlier
Collaborator
Collaborator

@Nick_Hall, you are right. That should of course be done before logout.

 

My question is: what part of the api do I need to call to get a specific property? In your example, you only get the latest created file in the Vault, but in our case, this won't work, because multiple files can be created at the same time by multiple users. I need it to be specific the file that the user is working on.

0 Likes

@Nick_Hall, you are right. That should of course be done before logout.

 

My question is: what part of the api do I need to call to get a specific property? In your example, you only get the latest created file in the Vault, but in our case, this won't work, because multiple files can be created at the same time by multiple users. I need it to be specific the file that the user is working on.

Message 4 of 8

Nick_Hall
Advocate
Advocate

@gert-leonvanlier 

 

In the code, you need to set the variable vaultFileName to the full Vault path of the file you want to get

FindLatestFilesByPaths returns the latest/current version of the file(s) you specify in the argument

 

What type of application are you creating - Vault add-in, AutoCAD add-in, stand-alone EXE, something else?

 

If you let me know I can give you better guidance

 

Nick

@gert-leonvanlier 

 

In the code, you need to set the variable vaultFileName to the full Vault path of the file you want to get

FindLatestFilesByPaths returns the latest/current version of the file(s) you specify in the argument

 

What type of application are you creating - Vault add-in, AutoCAD add-in, stand-alone EXE, something else?

 

If you let me know I can give you better guidance

 

Nick

Message 5 of 8

gert-leonvanlier
Collaborator
Collaborator

Ok. I think I understand. Not sure if I can start on it today, otherwise after the weekend.

 

It is an addition for an Inventor add in. This add in lets user fill in easy all the necessary properties that we need in the Vault, but right now we have to do a check on the Category Name.

0 Likes

Ok. I think I understand. Not sure if I can start on it today, otherwise after the weekend.

 

It is an addition for an Inventor add in. This add in lets user fill in easy all the necessary properties that we need in the Vault, but right now we have to do a check on the Category Name.

Message 6 of 8

gert-leonvanlier
Collaborator
Collaborator

@Nick_Hall 

 

I implemented the code as per your instruction, but categoryName gives me an empty string.

try
{
	fileIteration = GetFileIteration(vaultFileName, connection);
	string[] filePaths = { vaultFileName };
	Autodesk.Connectivity.WebServices.File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
	string categoryName = files[0].Cat.CatName;

	MessageBox.Show("Category Name = " + categoryName);
}

 

In this, for this particular file, Category Name should give me

Connectivity.VaultPro_B8iW4flRMn.png

 

Is CatName the same as Category Name?

0 Likes

@Nick_Hall 

 

I implemented the code as per your instruction, but categoryName gives me an empty string.

try
{
	fileIteration = GetFileIteration(vaultFileName, connection);
	string[] filePaths = { vaultFileName };
	Autodesk.Connectivity.WebServices.File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
	string categoryName = files[0].Cat.CatName;

	MessageBox.Show("Category Name = " + categoryName);
}

 

In this, for this particular file, Category Name should give me

Connectivity.VaultPro_B8iW4flRMn.png

 

Is CatName the same as Category Name?

Message 7 of 8

Nick_Hall
Advocate
Advocate
Accepted solution

@gert-leonvanlier 

 

I've tested this out and come up with this working code (apologies for using PowerShell, but it is very similar to C#

 

$serverIdentities = New-Object Autodesk.Connectivity.WebServices.ServerIdentities
$serverIdentities.DataServer = "192.168.1.100"
$serverIdentities.FileServer = "192.168.1.100"
// License model
$licenseType = [Autodesk.Connectivity.WebServices.LicensingAgent]::Client
// Login
$cred = New-Object Autodesk.Connectivity.WebServicesTools.UserPasswordCredentials($serverIdentities, "Vault", "Administrator", "*****", $licenseType)
$webSvc = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager($cred)
// Full file path in Vault 
[string]$vaultFileName = '$/Job PDFs/1017178/Manuals/1017178_ManualList.pdf'
// FindLatestFilesByPaths needs an array of strings
[string[]]$filePaths = ( $vaultFileName )
// Get the file  
[Autodesk.Connectivity.WebServices.File[]]$files = $webSvc.DocumentService.FindLatestFilesByPaths($filePaths)
// FindLatestFilesByPaths returns an array of files, so we only want the first
[Autodesk.Connectivity.WebServices.File]$file = $files[0]
// The file has the cathegory name in Cat.CatName 
[string]$categoryName = $file.Cat.CatName
Write-Host "File Path    : [$($vaultFileName)]"
Write-Host "File Name    : [$($file.Name)]"
Write-Host "Category Name: [$($categoryName)]"

 

This produces the following output

File Path : [$/Job PDFs/1017178/Manuals/1017178_ManualList.pdf]
File Name : [1017178_ManualList.pdf]
Category Name: [PDF Documentation]

Looking at the file in Vault

Nick_Hall_0-1664935337119.png

This code was tested on Vault 2021, but should be OK for 2022 & 2023

 

Looking at the issue you are having, I suspect that getting an empty string for categoryName is caused by not getting the file correctly. That happened when I was testing, and it was because I had a typo in the file name (line 10)

 

Hope it makes things a bit clearer

 

Nick

 

0 Likes

@gert-leonvanlier 

 

I've tested this out and come up with this working code (apologies for using PowerShell, but it is very similar to C#

 

$serverIdentities = New-Object Autodesk.Connectivity.WebServices.ServerIdentities
$serverIdentities.DataServer = "192.168.1.100"
$serverIdentities.FileServer = "192.168.1.100"
// License model
$licenseType = [Autodesk.Connectivity.WebServices.LicensingAgent]::Client
// Login
$cred = New-Object Autodesk.Connectivity.WebServicesTools.UserPasswordCredentials($serverIdentities, "Vault", "Administrator", "*****", $licenseType)
$webSvc = New-Object Autodesk.Connectivity.WebServicesTools.WebServiceManager($cred)
// Full file path in Vault 
[string]$vaultFileName = '$/Job PDFs/1017178/Manuals/1017178_ManualList.pdf'
// FindLatestFilesByPaths needs an array of strings
[string[]]$filePaths = ( $vaultFileName )
// Get the file  
[Autodesk.Connectivity.WebServices.File[]]$files = $webSvc.DocumentService.FindLatestFilesByPaths($filePaths)
// FindLatestFilesByPaths returns an array of files, so we only want the first
[Autodesk.Connectivity.WebServices.File]$file = $files[0]
// The file has the cathegory name in Cat.CatName 
[string]$categoryName = $file.Cat.CatName
Write-Host "File Path    : [$($vaultFileName)]"
Write-Host "File Name    : [$($file.Name)]"
Write-Host "Category Name: [$($categoryName)]"

 

This produces the following output

File Path : [$/Job PDFs/1017178/Manuals/1017178_ManualList.pdf]
File Name : [1017178_ManualList.pdf]
Category Name: [PDF Documentation]

Looking at the file in Vault

Nick_Hall_0-1664935337119.png

This code was tested on Vault 2021, but should be OK for 2022 & 2023

 

Looking at the issue you are having, I suspect that getting an empty string for categoryName is caused by not getting the file correctly. That happened when I was testing, and it was because I had a typo in the file name (line 10)

 

Hope it makes things a bit clearer

 

Nick

 

Message 8 of 8

gert-leonvanlier
Collaborator
Collaborator

@Nick_Hall 

I think I found out why it is not working. The variable vaultFileName in my case is just a string in the form xxx.ipt. So no file path. It has to be the path in Vault, thanks to your last reply.

 

I now got it working to change it to this:

try
{
	fileIteration = GetFileIteration(vaultFileName, connection);
	vaultFileName = "$/xxxx/Documents/" + vaultFileName;
	string[] filePaths = { vaultFileName };
	Autodesk.Connectivity.WebServices.File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
	Autodesk.Connectivity.WebServices.File file = files[0];
	string categoryName = file.Cat.CatName;

	MessageBox.Show("File Path = " + vaultFileName +
		"\nFile Name = " + file.Name +
		"\nCategory Name = " + categoryName);
}

 

This is the result:

Q26JF7tyqg.png

 

I now have to figure out how to get the file path, but that is not much of an issue.

 

Thank you very much!

@Nick_Hall 

I think I found out why it is not working. The variable vaultFileName in my case is just a string in the form xxx.ipt. So no file path. It has to be the path in Vault, thanks to your last reply.

 

I now got it working to change it to this:

try
{
	fileIteration = GetFileIteration(vaultFileName, connection);
	vaultFileName = "$/xxxx/Documents/" + vaultFileName;
	string[] filePaths = { vaultFileName };
	Autodesk.Connectivity.WebServices.File[] files = connection.WebServiceManager.DocumentService.FindLatestFilesByPaths(filePaths);
	Autodesk.Connectivity.WebServices.File file = files[0];
	string categoryName = file.Cat.CatName;

	MessageBox.Show("File Path = " + vaultFileName +
		"\nFile Name = " + file.Name +
		"\nCategory Name = " + categoryName);
}

 

This is the result:

Q26JF7tyqg.png

 

I now have to figure out how to get the file path, but that is not much of an issue.

 

Thank you very much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report