Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically add NewLines to a TFS work item textbox?

I have a web system that has a few hooks into our TFS work item system. One of the things I am trying to do is that when a certain action is performed, it takes the current text in one field and makes a comment in the "General Comments" field announcing what the field was previously (Yes I know, history contains this but the higher ups want this in the gen comments).

The problem I am having is that TFS seems to be ignoring Environment.NewLines that I have in my string. So with this code:

                    item.Fields[GENCOMMENTS].Value = string.Concat(DateTime.Now.ToShortDateString()
                                , " - QA Dashboard - Required By Date Reason set to \"Hotfix\", but previously contained \""
                                , item.Fields[REQBYDTREASON].Value.ToString()
                                , "\"."
                                , Environment.NewLine
                                , Environment.NewLine
                                , Environment.NewLine
                                , item.Fields[GENCOMMENTS].Value.ToString());

So assuming my general comments section contains:

THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS

I get the following output in the general comments section when the work item is saved

9/29/2010 - QA Dashboard - Required By Date Reason set to "Hotfix", but previously contained "hotfixtest".THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS

Why is it ignoring the new lines and how can I get a new line into the work item?

Thanks,

like image 641
KallDrexx Avatar asked Sep 29 '10 20:09

KallDrexx


2 Answers

TFS work item content is often processed as HTML. That's likely happening here and hence it's ignoring the extraneous newlines in the text. Try wrapping the content in a <pre> block or using <p> and see if that fixes the issue.

like image 112
JaredPar Avatar answered Nov 13 '22 00:11

JaredPar


RTF or HTMl controls will use and render html markup - so depends on the control. Try adding and formatting rich text to a multiline control and then debug it in a console app - browse the field value - you'll see html tags.

like image 1
Andy Avatar answered Nov 13 '22 02:11

Andy