Attachment download


  • Hi,

    I am trying to extract attachment from TFS back to file system through OM API. In beta2 there was Attachment.CopyTo method. It is not there in beta 3 refresh. The only thing I found is DownloadFile method of ClientService, but if it is correct path, how I can get AttachmentId?

    Can anybody point me in right direction?

    Thanks in advance,


    Wednesday, January 18, 2006 6:32 PM


  • Leon, sorry for delay in responding to your question. We see that attachment id is not exposed in OM, and hence using WS is harder. Instead below is a simple function to download data directly from attachment Url which is exposed in object model:

    private static void DownloadFile(string attachmentUrl, string targetFile)


        using (WebClient wc = new WebClient())


            wc.Credentials = CredentialCache.DefaultCredentials; ;

            byte[] b = wc.DownloadData(attachmentUrl);


            FileStream fs = File.Create(targetFile );

            fs.Write(b, 0, b.Length);




    AttachmentUrl is exposed in Attachment object. You could get the file name part by parsing the Url and appending target folder name with some code changes.


    Monday, January 23, 2006 2:02 AM