【问题标题】:Download File from AutoDesk Vault (Vault 2015 SDK) with c# code giving error从 AutoDesk Vault (Vault 2015 SDK) 下载文件,c# 代码给出错误
【发布时间】:2015-07-10 09:15:41
【问题描述】:

我正在尝试使用 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); 收到错误。 我可以手动下载文件,但不能以编程方式下载。我究竟做错了什么 ? 如果我能获得一些示例代码来下载基于元数据的文件,那就太好了。

谢谢!

【问题讨论】:

    标签: c# autodesk autodesk-vault


    【解决方案1】:

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

    请参阅对象的 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);
    

    【讨论】:

    【解决方案2】:

    我修改了

    FilestoreService fileStoreService = new FilestoreService()
    

    FilestoreService fileStoreService = serviceManager.FilestoreService
    

    在问题中截取的代码中,它起作用了。

    【讨论】:

      猜你喜欢
      • 2015-10-02
      • 1970-01-01
      • 2019-04-21
      • 2013-07-21
      • 1970-01-01
      • 2018-09-27
      • 2014-05-14
      • 1970-01-01
      • 2022-10-24
      相关资源
      最近更新 更多