从AutoDesk Vault(Vault 2015 SDK)下载文件,其中包含错误的c#代码

时间:2015-04-30 15:21:35

标签: c# autodesk autodesk-vault

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

  

请求失败,HTTP状态为404:Not Found"执行相应的代码行以下载文件。

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

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);处获取错误。 我可以手动下载文件,但不能以编程方式下载。我究竟做错了什么 ? 如果我可以根据元数据获取一些示例代码来下载文件,那就太棒了。

谢谢!

2 个答案:

答案 0 :(得分:4)

下载您想要的文件"获取"它们。

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

答案 1 :(得分:0)

我修改了

FilestoreService fileStoreService = new FilestoreService()

FilestoreService fileStoreService = serviceManager.FilestoreService

在问题中发布的代码剪切并且有效。