Download Attachments

Applies to QAComplete 14.3, last modified on February 19, 2024

The sample code below shows how to download files attached to a defect in your project in QAComplete. The code uses the Attachments_GetAttachment operation to load the needed file. The AttachmentId parameter of the operation specifies the ID of the attachment that contains the file you want to download.

You can use the operation to download files attached to item of other types (release, requirement, and so on) the same way you download the defect’s attachments. To do this, specify the ID of the item’s attachment that stores the file you want to download.

C#

string login = "[email protected]";
string password = "p@ssword";
int projId = 10372;
// The ID of the attachment to download
int Id = 12;
string filePath = "C:\\Work\\export.txt";

ServiceSoapClient service = new ServiceSoapClient();

// Preparing AuthenticationData
LoginInfo loginInfo = service.GetLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.AppCode = loginInfo.AppCode;
authData.UserId = loginInfo.UserId;
authData.PassCode = password;
authData.DeptId = loginInfo.DeptId;
authData.ProjId = projId;

// Saving an attachment to a file
byte[] file = service.Attachments_GetAttachment(authData, Id);
System.IO.File.WriteAllBytes(filePath, file);
Console.WriteLine("File was saved");

Java

import java.io.FileOutputStream;

String login = "[email protected]";
String password = "p@ssword";
int projId = 10372;
// The ID of the attachment to download
int Id = 12;
String filePath = "C://Work//export.txt";

ServiceSoap service = new Service().getServiceSoap12();

// Preparing AuthenticationData
LoginInfo loginInfo = service.getLoginInfo("", login, password);
AuthenticationData authData = new AuthenticationData();
authData.setAppCode(loginInfo.getAppCode());
authData.setUserId(loginInfo.getUserId());
authData.setPassCode(password);
authData.setDeptId(loginInfo.getDeptId());
authData.setProjId(projId);

// Saving an attachment to a file
try
{
  byte[] attach = service.attachmentsGetAttachment(authData, Id);
  FileOutputStream file = new FileOutputStream(filePath);
  file.write(attach);
  file.close();
  System.out.println("File was saved");
}
catch (Exception e) {
  e.printStackTrace();
}

See Also

Attachments_GetAttachment Operation
How To Get Items
How To

Highlight search results