Unanswered How to write data to a HTML Work Item Field via the TFS API?

  • Thursday, April 26, 2012 9:59 AM
     
     

    Good morning,

    When using a "HTML" field type in a work item defintion, is it possible .. or how is it possible to write raw html to it? Basically when writing to workitem.Fields["MyHtmlField"].Value the html string, it apparently gets escaped, so next time I load it I get e.g. <p>sometext</p> .. etc instead of sometext in a paragraph.

    How would i do that?

    Best regards and thanks,

    -Jörg

All Replies

  • Monday, April 30, 2012 8:04 AM
    Moderator
     
     

    Hello Jörg,

    As far as I know that the HTML field in the TFS work item does not only contain the string value but also contain the formate styles. So if you would like to write data to the HTML field via TFS API, you need to first convert these formated characters to escaped characters and then add the escaped characters to the HTML field.

    Thanks.


    Vicky Song [MSFT]
    MSDN Community Support | Feedback to us

  • Friday, May 04, 2012 5:04 PM
     
      Has Code

    Hi Jörg,

    To convert plain text to HTML try to use use following method and the simply assign the converted string to your HTML field.        

    String htmlText = System.Web.HttpUtility.HtmlEncode(plainText);
    m_workItem.Fields[HTMLFieldName].Value = htmlText;

    I hope it helps

    Regards, Saludos

    ezien

    • Proposed As Answer by ezien Friday, May 04, 2012 8:00 PM
    • Unproposed As Answer by jbattermann Friday, May 04, 2012 8:33 PM
    •  
  • Friday, May 04, 2012 8:36 PM
     
     

    Good evening ezien,

    thanks for your proposed answer, but I was not refering to a 'normal' html field, but the Test Steps one in Test Cases which are not HTML per se, just stored in a field of that type. The data format is in fact different and I have problems writing that particular data to the field.

    Best regards,

    -J