Simple vault upload example without associations

Simple vault upload example without associations

Anonymous
Not applicable
3,233 Views
7 Replies
Message 1 of 8

Simple vault upload example without associations

Anonymous
Not applicable

Hi folks,

Can someone please point me to a very basic vault upload example using generic files which are not related to Inventor or AutoCAD or any specific product?  I want to stay away from dealing with associations and keep it very simple for this.  I just need to create a folder in Vault (if it doesn't yet exist) and upload some files with versioning so I can check-in more recent versions later.  An example using VB.NET would be most helpful.  Many thanks!

Best regards,
-- Jeff

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

mike_ponti
Enthusiast
Enthusiast

Jeff, I personally don't have any sample code for you, but if you look in the chm file in the docs folder of the Vault SDK, the knowledge base section has an article called "How to aquire files". At the end of the article is some code for using the webservicemanager with adding and checking in files. It's for an older version of Vault, but I expect it still applies.

 

You can also find these articles on "It's just ones and zeros" blog.

 

HTH,

Mike

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hi Mike,

Thanks for your reply.  Yeah, I've been through a bunch of that stuff, but so much of it is tailored for the more typical usage with Inventor or AutoCAD files that have associations with related files and what-not.  And Doug's blog has tons of info, but I'm really just looking for one simple piece without all the distractions.

I've managed to get a file into the vault mainly using just the FileManager.AddFile() function, but for some reason, I can only put it at the very root of the vault presently - if I try to put it into any existing folder (or folder in a folder, etc.) in the vault, it does not work.  Hopefully, I'll get that resolved soon and will be out of the weeds.  Thanks again.

Best regards,
--Jeff

0 Likes
Message 4 of 8

mike_ponti
Enthusiast
Enthusiast

vault and simple usually don't go well together 🙂

 

If you really want to see what the vault client does when you upload a file to a folder, use a tool like Fiddler to spy on the http calls the vault client makes to perform the operation. The vault client is really nice that way in the sense that nothing is hidden. You will be able to see each of the api calls and the  parameters it sends during the operation. It's labor intensive, but a good code editor that will format the xml for you helps make things readable.

0 Likes
Message 5 of 8

Markus.Koechl
Autodesk
Autodesk
Accepted solution

Hi Jeff,

As you can add a file to the root, but not to a given folder, I got the idea that you miss converting the WebService.Folder object to the IEntity folder. Let me put this into this way: vaultfolder = conn......GetFolderByPath("$/Documents/") wrapped into the IEntity Folder object will work.

 

 

Compare the code below that I am using to add single PDF or Xlsx files to Vault:

 

// upload file to Vault
                Folder vaultFolder = conn.WebServiceManager.DocumentService.FindFoldersByPaths(settings.ReportsVaultPath.ToSingleArray()).First();
                if (vaultFolder == null || vaultFolder.Id == -1)
                    throw new Exception("Vault reports folder " + settings.ReportsVaultPath + " not found");

                var folderEntity = new Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder(conn, vaultFolder);
                try
                {
                    addedFile = conn.FileManager.AddFile(folderEntity, "Created by Job Processor", null, null, FileClassification.None, false, vdfPath);
                }
                catch
                {
                    throw new Exception("Job could not add report file " + vdfPath);
                }

 



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
Message 6 of 8

Anonymous
Not applicable

Hi Markus,

Thank you very much for that useful piece of information.  Sorry I had to divert from this project to tackle something else lately, but this is what I needed to know.  Cheers!

Best regards,
--Jeff

0 Likes
Message 7 of 8

clastrilla
Advocate
Advocate

Hi Markus, thanks for this tip. I'm trying to do this in powerShell, but 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
$fileAssoc = New-Object Autodesk.Connectivity.WebServices.FileAssoc $null
$addedFile = $vaultConnection.FileManager.AddFile($vaultFolder,"Added by powerShell", $fileAssoc, $null, $fileClassification, $false, $fileFromDisk)
Show-Inspector

 

But it's giving me an error: Cannot find an overload for "AddFile" and the argument count: "7".
At D:\CAL Data\CG Projects\powerShell\UploadingAFile.ps1:26 char:1
+ $addedFile = $vaultConnection.FileManager.AddFile($vaultFolder,"Added ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest

 

I'm trying to understand your comment that the $vaultFolder object needs to be wrapped in an iEntity folder object, but I'm getting stuck on how to do that. Any tips would be much appreciated.

 

I also posted this question here.

0 Likes
Message 8 of 8

clastrilla
Advocate
Advocate

Found it - please see this link

0 Likes