Hi,
I was hoping I could ge some assistance with my code below - I am stuck on this and my programming knowledge is not that great to be honest. I am using Data Standard and the "createFolder.ps1" to produce a Standard Folder Structure when creating a new "Project" category folder.
I additionally want to add some files like word and excel documents to a particular folder after craetion. Folders are created fine and the categories assigned but I cannot get the AddFile method t produce any results in my Vault Explorer.
Please find code abstract below and resulting log - Any help would be greatly appreaciated.
$folder = $vault.DocumentService.GetFolderById($folderId)
$path = $folder.FullName+"/"+$dialog.CurrentFolder.Name
$subFolder = $vault.DocumentService.GetFolderByPath($path)
$dsDiag.Trace(" subFolder: " + $subFolder.Name)
$categoryId = $vault.CategoryService.GetCategoriesByEntityClassId("Folder",$true)
$subFolder1 = $vault.DocumentServiceExtensions.AddFolderWithCategory("00-Bid Details and Project Briefing", $dialog.CurrentFolder.Id, $false, $categoryId[6].Id)
#$subFolder1 = [Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities]::Folder
$dsDiag.Trace(" subFolder1: " + $subFolder1.Name)
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Autodesk\Vault Professional 2015\Explorer\Autodesk.DataManagement.Client.Framework.Vault.dll")
$file = [Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities]::FileIteration
$fileClassification = [Autodesk.Connectivity.WebServices.FileClassification.Source]::None
# $fileAssociation = [Autodesk.Connectivity.WebServices.FileAssocParam]::None
$fileFromDisk = New-Object Autodesk.DataManagement.Client.Framework.Currency.FilePathAbsolute "C:\Temp\Contact List.doc"
$dsDiag.Trace(" fileFromDisk: " + $fileFromDisk.FullPath)
$file = New-Object Autodesk.DataManagement.Client.Framework.Vault.Services.Connection.FileManager.AddFile $subFolder1, "TEST", $null, $null, $fileClassification, $false, $fileFromDisk
$dsDiag.Trace(" File Name: " + $file.EntityName)
11:25:04:638: >> GetParentFolderName
11:25:05:141: True
11:25:05:156: subFolder: 642696 - sadas
11:25:05:196: subFolder1: 00-Bid Details and Project Briefing
11:25:05:199: fileFromDisk: C:\Temp\Contact List.doc
11:25:05:201: File Name:
11:25:05:506: << CreateFolder PSI
11:25:05:507: ============Results================
11:25:05:507: Autodesk.DataManagement.Client.Framework.Vault, Version=19.0.0.0, Culture=neutral, PublicKeyToken=aa20f34aedd220e1
11:25:05:507: Autodesk.Connectivity.Explorer.Extensibility, Version=19.0.0.0, Culture=neutral, PublicKeyToken=aa20f34aedd220e1
11:25:05:507: ===================================
Many thanks & regards, Vas
Hi,
The following line is wrong:
$file = New-ObjectAutodesk.DataManagement.Client.Framework.Vault.Services.Connection.FileManager.AddFile $subFolder1, "TEST", $null, $null,$fileClassification, $false, $fileFromDisk
AddFile is a method of the IFileManager interface. Therefore you have to call AddFile like this:
$file = $vaultConnection.FileManager.AddFile($subFolder1, "TEST", $null, $null,$fileClassification, $false, $fileFromDisk)
In looking for a way to upload files via powerShell, I've come across this post. Feels like I'm getting closer with this code:
$vaultFolder = $vault.DocumentService.FindFoldersByPaths("$/Resources")
$fileFromDisk = New-Object Autodesk.DataManagement.Client.Framework.Currency.FilePathAbsolute "C:\Temp\ExportedNumber.csv"
$fileClassification = New-Object Autodesk.Connectivity.WebServices.FileClassification
$addedFile = $vaultConnection.FileManager.AddFile($vaultFolder,"Added by powerShell", $null, $null, $fileClassification, $false, $fileFromDisk)
Show-Inspector
But I'm getting an error:
Cannot find an overload for "AddFile" and the argument count: "7".
At D:\CAL Data\CG Projects\powerShell\UploadingAFile.ps1:23 char:1
+ $addedFile = $vaultConnection.FileManager.AddFile($vaultFolder,"Added ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
I realise powerVault has Add-File commandlet, but trying to see how to do it just via powerShell.
Can't seem to figure it out - any help would be much appreciated! Thanks in advance!
The error that you are reporting typically comes from missing type definitions; Powershell does not enforce them, but Vault API cannot handle "PSObject" so you need to declare all input parameters that are not null. Unfortunately, I don't have a Powershell code for this at my fingertips. But you should be able to get the idea from a C# sample as well.
//add resulting export file to Vault if it doesn't exist, otherwise update the existing one
ACW.Folder mFolder = mWsMgr.DocumentService.FindFoldersByIds(new long[] { mFile.FolderId }).FirstOrDefault();
string vaultFilePath = System.IO.Path.Combine(mFolder.FullName, mExportFileInfo.Name).Replace("\\", "/");
ACW.File wsFile = mWsMgr.DocumentService.FindLatestFilesByPaths(new string[] { vaultFilePath }).First();
VDF.Currency.FilePathAbsolute vdfPath = new VDF.Currency.FilePathAbsolute(mExportFileInfo.FullName);
VDF.Vault.Currency.Entities.FileIteration vdfFile = null;
VDF.Vault.Currency.Entities.FileIteration addedFile = null;
VDF.Vault.Currency.Entities.FileIteration mUploadedFile = null;
if (wsFile == null || wsFile.Id < 0)
{
// add new file to Vault
mTrace.WriteLine("Job adds " + mExportFileInfo.Name + " as new file.");
if (mFolder == null || mFolder.Id == -1)
throw new Exception("Vault folder " + mFolder.FullName + " not found");
var folderEntity = new Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder(connection, mFolder);
try
{
addedFile = connection.FileManager.AddFile(folderEntity, "Created by Job Processor", null, null, ACW.FileClassification.DesignRepresentation, false, vdfPath);
mExpFile = addedFile;
}
catch (Exception ex)
{
throw new Exception("Job could not add export file " + vdfPath + "Exception: ", ex);
}
}
else
{
Thanks Markus. I've tried declaring the input parameters as below:
$vaultFolder = $vault.DocumentService.FindFoldersByPaths("$/Resources")
$folderEnt = New-Object Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder($vaultConnection, $vaultFolder)
$fileFromDisk = New-Object Autodesk.DataManagement.Client.Framework.Currency.FilePathAbsolute "C:\Temp\ExportedNumber.csv"
$fileClassification = New-Object Autodesk.Connectivity.WebServices.FileClassification
$fileAssoc = New-Object Autodesk.Connectivity.WebServices.FileAssoc $null
$addedFile = $vaultConnection.FileManager.AddFile($folderEnt,"Added by powerShell", $fileAssoc, $null, $fileClassification, $false, $fileFromDisk)
As in your other post, you recommended that the $folderEnt should be wrapped in an iEntity folder object. I tried doing that but my $folderEnt is throwing a similar error:
New-Object : Cannot convert argument "1", with value: "Autodesk.Connectivity.WebServices.Folder[]", for "Folder" to type
"Autodesk.Connectivity.WebServices.Folder": "Cannot convert the "Autodesk.Connectivity.WebServices.Folder[]" value of type
"Autodesk.Connectivity.WebServices.Folder[]" to type "Autodesk.Connectivity.WebServices.Folder"."
At D:\CAL Data\CG Projects\powerShell\UploadingAFile.ps1:18 char:14
+ ... folderEnt = New-Object Autodesk.DataManagement.Client.Framework.Vault ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
I seem to be missing a beat (or more) here...
Thanks in advance!
Fixed! A colleague of mine showed how to wrap it in an iEntity object:
$vFolderArr = $vault.DocumentService.FindFoldersByPaths("$/Resources")
$vaultFolder=New-Object Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder $vaultConnection, $vFolderArr[0]
$fileFromDisk = New-Object Autodesk.DataManagement.Client.Framework.Currency.FilePathAbsolute "C:\Temp\ExportedNumber.csv"
$addedFile = $vaultConnection.FileManager.AddFile($vaultFolder,"Added by powerShell", $null, $null, [Autodesk.Connectivity.WebServices.FileClassification]::None, $false, $fileFromDisk)
It seems my syntax for the Folder constructor was incorrect, and I needed to pass the specific instance of the folder in the array.
Hi, I know it's been a while since this post, I'm trying to do the same, add a file to vault using AddFile but I'm having a problem getting $vaultConnection.