For a Bug entity in VSTS, while fetching inline image input stream of an inline image in HTML field, C# WebClient.DownloadData() fetches corrupted data and a data of fixed size irrespective of the size of the data hosted at that URI RRS feed

  • Question

  • The code is in C#. We are using Visual Studion 2015 community edition and Microsoft Team Foundation Server Object Model 2012 and .NET framework 4.0 or higher.

    Attachment URI variable value for below code :


    The snippet of the code is mentioned below.

    WebClient webClient = new WebClient();
    webClient.Credentials = (ICredentials)connectionInfo.tfsServerConfig.Credentials;
        // 1. Approach 1 using webClient.DownloadFile() which downloads the file in current directory locally
        webClient.DownloadFile(attachmentURI, "aoaob.png");
        // 2. Approach 2 using webClient.DownloadData() which loads the byte array of the attachment hosted at given // attachment URI
        byte[] data = webClient.DownloadData(attachmentURI);
        return data;

    Using the above code, we have tried accessing the same inline image (in any HTML field of an entity) hosted in TFS versions 2013, 2015, and 2017. For each versions of TFS, we are able to load a correct inline image attachment input stream. But on the contrary, using the same code and other infrastructures, we have tried loading the attachment input stream in Microsoft VSTS (same entity and same HTML field), and every time we get a corrupted PNG file of approximately 14 KB size irrespective of the size of the image being fetched by using the above attachment URI. The original size of the PNG image hosted at above attachment URI is 113 KB.

    But, still we are not able to get a correct input stream in entity in Microsoft VSTS using the above method (while correct image loaded in TFS all versions mentioned above).

    Please help us to resolve this issue or tell us anything that we are doing wrong.

    Monday, November 27, 2017 3:39 PM

All replies

  • I suspect you need to capture the cookies and pass those into the image download request. VSTS relies on OAuth for a lot of things.

    My blog: blog.jessehouwing.nl

    Monday, November 27, 2017 7:15 PM
  • Thanks for the prompt reply.

    Can you please tell us as to which cookies have to be included for fetching the data of an attachment which is an inline image in a HTML field of an entity Bug in VSTS?

    Wednesday, November 29, 2017 7:01 AM