0

I have recently started using C# over the past year so I'm somewhat new to this, but can usually hack through things with some effort, but this one is eluding me. We use TestTrack for development bug/issue tracking at our company. I've created a custom windows forms app to be the front-end to TestTrack for one of our departments. It connects using SOAP. I'm not using WPF/WCF and don't want to go that route. I'm having difficulty finding any examples of how to correctly encode a file for attachment that is a PDF. The code below does actually create an attachment in TestTrack to an already-existing issue, but when you try to open it in TestTrack, it pops up an error message that says "Insufficient Data For An Image". The example below does work if you're wanting to add a text file to TestTrack using SOAP. I'm wanting to know what I need to change below so that I can get a PDF file into TestTrack and then be able to open it in the TestTrack application without the error mentioned above. Thanks in advance for any input/help.

    public void getAttachments(long lSession, CDefect def)
    {
        ttsoapcgi cgiengine = new ttsoapcgi();

        // Lock the defect for edit.
        CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);

        string attachment = "c:\\TEST\\TEST_PDF.PDF";

        CFileAttachment file = new CFileAttachment();
        file.mstrFileName = Path.GetFileName(attachment);

        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

        StreamReader reader = new StreamReader(attachment);
        file.mstrFileName = Path.GetFileName(attachment);
        file.mpFileData = enc.GetBytes(reader.ReadToEnd());
        reader.Close();

        CReportedByRecord reprec = lockedDefect.reportedbylist[0];
        CFileAttachment[] afile = reprec.attachmentlist;
            if (afile == null)
            {
                lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
                lockedDefect.reportedbylist[0].attachmentlist[0] = file;
            }

            // Save our changes.
            cgiengine.saveDefect(lSession, lockedDefect);
    }
}
ARW3
  • 1
  • Go figure. I found an answer to my solution within an hour of asking for help. Geez. Anyhow, I'm happy. :-) I will post my answer in a few hours once this site allows me to do so. – ARW3 Jan 23 '13 at 22:23

1 Answers1

0

Here is the modified method that allowed me to attach a PDF to SOAP and get it into TestTrack as an attachment to an issue:

        public void getAttachments(long lSession, CDefect def)
    {
        ttsoapcgi cgiengine = new ttsoapcgi();

        // Lock the defect for edit.
        CDefect lockedDefect = cgiengine.editDefect(lSession, def.recordid, "", false);

        string attachment = "c:\\TEST\\TEST_PDF.PDF";

        CFileAttachment file = new CFileAttachment();

        file.mpFileData = File.ReadAllBytes(attachment);
        file.mstrFileName = Path.GetFileName(attachment);

        CReportedByRecord reprec = lockedDefect.reportedbylist[0];
        CFileAttachment[] afile = reprec.attachmentlist;
            if (afile == null)
            {
                lockedDefect.reportedbylist[0].attachmentlist = new CFileAttachment[1];
                lockedDefect.reportedbylist[0].attachmentlist[0] = file;
            }

            // Save our changes.
            cgiengine.saveDefect(lSession, lockedDefect);
    }
ARW3
  • 1