开发者

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

开发者 https://www.devze.com 2023-01-17 23:11 出处:网络
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

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.Conc开发者_如何学编程at(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,


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消