C# Download Test files and Attachments
/*
 * How to operate
  TestFactory tempTestF = (TestFactory)tdConnection.TestFactory;
  Test tempTest = (Test)tempTestF[8];
  TestFilesAndAttachments(tempTest);
 */
public void TestFilesAndAttachments(Test theTest)
{
  /*
     Download test files and attachments
    
     This routine gets a test object and
      first downloads the script files and then the attachments.
     The debug outputs are based on test:
     "OTA_DEMO_SUBJECT\OTA_SUBJECT_level1\OTA_SUB_1.2\SimpleVAPI-XP"
   */
  AttachmentFactory testAttachFact;
  List attachList;
  IExtendedStorage testStorage, testAttachStorage;
  String testDownLoadPath, attachDownLoadPath, ownerType;
  bool isFatalErr;
  object ownerKey;
  String tempStr = String.Empty;
  attachDownLoadPath = String.Empty;
  //Get the test storage.
  List nullList;
  testStorage = theTest.ExtendedStorage;
  testStorage.ClientPath = @"C:\" + theTest.Name + @"\testStorage";
  
  //Use IExtendedStorage.LoadEx to get the test files.
  testDownLoadPath = testStorage.LoadEx("", true, out nullList, out isFatalErr);
  tempStr = String.Format("Fatal error = {0}", isFatalErr);
  Debug.Print(tempStr);
  tempStr = String.Format("The test download path: {0}", testDownLoadPath);
  Debug.Print(tempStr);

  //Get the Attachments.
  testAttachFact = theTest.Attachments;
  testAttachFact.FactoryProperties(out ownerType, out ownerKey);
  tempStr = String.Format("ownerType = {0}, ownerKey = {1}", ownerType, ownerKey);
  Debug.Print(tempStr);

  /*
   Get the list of attachments and go through
   the list, downloading one at a time.
   */
  attachList = testAttachFact.NewList("");
  foreach (Attachment tempAttach in attachList)
  {
    Debug.WriteLine("----------------------------");
    Debug.WriteLine("Download attachment");
    Debug.WriteLine("Before setting path");
    tempStr = String.Format("The attachment name: {0}", tempAttach.Name[0]);
    Debug.Print(tempStr);
    tempStr = String.Format("The attachment server name: {0}", tempAttach.ServerFileName);
    Debug.Print(tempStr);
    tempStr = String.Format("The filename: {0}", tempAttach.FileName);
    Debug.Print(tempStr);
    /*
     Before setting path
     The attachment Name: TEST_98_SampleAttachment.txt
     The attachment server name: C:\Program Files\Mercury Interactive\Quality Center\repository\qc\Default\Steve_85_Doc\Attach\TEST_98_SampleAttachment.txt
     The filename: C:\DOCUME~1\steves\LOCALS~1\Temp\TD_80\423af35f\Attach\TEST98\TEST_98_SampleAttachment.txt
     */
    testAttachStorage = tempAttach.AttachmentStorage;
    testAttachStorage.ClientPath = @"C:\" + theTest.Name + @"\attachStorage";
    tempAttach.Load(true, ref attachDownLoadPath);
    Debug.Print("\r\n After download");
    tempStr = String.Format("Down load path: {0}", attachDownLoadPath);
    Debug.Print(tempStr);
    tempStr = String.Format("The filename: {0}", tempAttach.FileName);
    Debug.Print(tempStr);
  }
}