1

我正在尝试使用C#代码从 Vault(Vault 2015 SDK)下载文件。尝试了与此处提到的完全相同的方法:http: //inventorhub.autodesk.com/discussions/threads/301/post/5600165 但出现错误

在执行下载文件的相应代码行时,请求失败,HTTP 状态为 404:未找到”。

请在下面找到我的示例代码:

using Autodesk.Connectivity.WebServicesTools;
using Autodesk.Connectivity.WebServices; 

UserPasswordCredentials login = new UserPasswordCredentials("servername", "myVault", "username", "Password", true);
using (WebServiceManager serviceManager = new WebServiceManager(login))
{
    Autodesk.Connectivity.WebServices.Folder folder = serviceManager.DocumentService.GetFolderByPath("$/Myfolder");
    Autodesk.Connectivity.WebServices.File[] files = serviceManager.DocumentService.GetLatestFilesByFolderId(folder.Id, false);
    if (files != null && files.Any())
    {
        foreach (Autodesk.Connectivity.WebServices.File file in files)
        {
            //Sample code to download the files
            string localPath = AppDomain.CurrentDomain.BaseDirectory;
            Autodesk.Connectivity.WebServices.File localFile = serviceManager.DocumentService.GetFileById(file.Id);
            var FileDownloadTicket = serviceManager.DocumentService.GetDownloadTicketsByFileIds(new long[] { file.Id });
            FilestoreService fileStoreService = new FilestoreService();
            var fileBytes = fileStoreService.DownloadFilePart(FileDownloadTicket[0].Bytes, 0, localFile.FileSize, false);
            System.IO.File.WriteAllBytes(localPath, fileBytes);
        }
    }
}

得到错误fileStoreService.DownloadFilePart(FileDownloadTicket[0].Bytes, 0, localFile.FileSize, false);。我可以手动下载文件,但不能以编程方式下载。我究竟做错了什么 ?如果我能获得一些示例代码来下载基于元数据的文件,那就太好了。

谢谢!

4

2 回答 2

5

对于下载文件,您要“获取”它们。

请参阅对象的 SDK 文档: Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections.Connection

创建连接对象后,使用它来获取文件(注意这也是签出文件的方式):

using VDF = Autodesk.DataManagement.Client.Framework;

var acquireSettings = new VDF.Vault.Settings.AcquireFilesSettings(
    connection, updateFileReferences: false);

foreach (var file in files)
{
    acquireSettings.AddFileToAcquire(
        new VDF.Vault.Currency.Entities.FileIteration(connection, file),
        VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
}

VDF.Vault.Results.AcquireFilesResults results = connection.FileManager.AcquireFiles(acquireSettings);
于 2015-05-13T16:34:47.890 回答
1

我修改了

FilestoreService fileStoreService = new FilestoreService()

FilestoreService fileStoreService = serviceManager.FilestoreService

在问题中发布的代码中,它起作用了。

于 2015-10-23T17:43:20.333 回答