Move files by API

Move files by API

ppauleSHGR6
Enthusiast Enthusiast
185 Views
2 Replies
Message 1 of 3

Move files by API

ppauleSHGR6
Enthusiast
Enthusiast

Hi everyone,

 

I've created a custom job to move files to another folder and I'm facing problems with it.

 

I've read this is an already built-in feature but I can't find it in Vault Professional 2023.

The documentation says:

Move files in a vault

  1. Select a file or files.
  2. From the Edit menu, select Move to Folder.
  3. In the Select Vault Location dialog box, browse for the new location in the vault and then click OK.

Official link: https://help.autodesk.com/view/VAULT/2023/ENU/?guid=GUID-832F39E3-D97E-4BC5-81BC-38143FBB47A0

I don't know what they mean by "Edit menu" and I can't see the "Move to Folder" function anywhere on the UI in the client.

 

The problem I am facing with my own implementation of this feature is the following:

After a Inventor model was moved to another folder, checked out, modified, saved and tried to be checked-in again, an error appears that the "dwf" file already exists with the same name.

 

ppauleSHGR6_0-1749641471795.png

"A file with this name is already existing in the Vault".

 

Basically all I do is executing the following code line from the context menu of selected files:

serviceManager.DocumentService.MoveFile(file.MasterId, file.FolderId, targetFolder.Id);

 

Does this API method requiere to move the associated DWF file separately?

 

All help is very much appreciated.

Thanks!

 

0 Likes
Accepted solutions (1)
186 Views
2 Replies
Replies (2)
Message 2 of 3

g.georgiades
Advocate
Advocate
Accepted solution

Hi @ppauleSHGR6 

 

Yes you must move the dwf manually and ensure it is always located next to the file it is associated with.

 

Vault creates an association behind the scenes, so you can access it by getting the file associations of the file with the hidden option true.

You could also query vault for the file name directly since, unless you change job processor settings, dwf files have a known naming scheme.

 

Here is a code snippet from what I use that gets attachments of DWFs children (and pdf parents)

 

//include hidden to get DWFs

File fil; //get the file from somewhere
File attachedDWF = null;
File attachedPDF = null;

var assocsLists = mVltCon.WebServiceManager.DocumentService.GetLatestFileAssociationsByMasterIds(new[] { fil.MasterId }, 
        FileAssociationTypeEnum.Attachment, false, FileAssociationTypeEnum.Attachment, false, true, true, false);

if(assocsLists == null || assocsLists.Length == 0)
	return;

foreach(var ascList in assocsLists)
{
	if(ascList.FileAssocs == null || ascList.FileAssocs.Length == 0)
		continue;

	foreach(var asc in ascList.FileAssocs)
	{
		//pdfs are parent attachemnts (i set)
		if(asc.Typ == AssociationType.Attachment && asc.ParFile.Name.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase))
		{
			string dwgName = System.IO.Path.GetFileNameWithoutExtension(fil.Name);
			string pdfName = System.IO.Path.GetFileNameWithoutExtension(asc.ParFile.Name);
			if(dwgName.Equals(pdfName, StringComparison.CurrentCultureIgnoreCase))
				attachedPDF = asc.ParFile;
		}
		//dwfs are child attachments (vault sets)
		if(asc.Typ == AssociationType.Attachment && (asc.CldFile.Name.EndsWith(".dwf", StringComparison.CurrentCultureIgnoreCase) || asc.CldFile.Name.EndsWith(".dwfx", StringComparison.CurrentCultureIgnoreCase)))
		{
			string dwfName = System.IO.Path.GetFileNameWithoutExtension(asc.CldFile.Name); //dwf files autogen with .xxx.dwf
			if(dwfName.Equals(fil.Name, StringComparison.CurrentCultureIgnoreCase))
				attachedDWF = asc.CldFile;
		}
	}
}

 

 

 

Also the move to folder button is here

ggeorgiades_0-1749726991663.png

 

 

Message 3 of 3

ppauleSHGR6
Enthusiast
Enthusiast

Hi @g.georgiades 

 

thanks for your advice and for sharing a code snippet!

It helped me to implement and complete the feature.

 

0 Likes