1

I have been working on a small winform c# App that will enable me to create a work item in TFS without having to actually go on the TFS server. I have figured out how to add the title, attachments, description etc. However I cant seem to figure out how to insert a local image into the TFS work Item "Repro Steps" field. Here is my code so far.

Uri collectionUri = new Uri("Server Adress" + project);
TfsTeamProjectCollection server = new TfsTeamProjectCollection(collectionUri);
WorkItemStore store = (WorkItemStore)server.GetService(typeof(WorkItemStore));

WorkItem workItem = store.Projects[SubProject].WorkItemTypes["Bug"].NewWorkItem();
workItem.Title = "Title";
workItem.IterationPath = "Iteration";
workItem.AreaPath = "Area"; 

workItem.Fields["repro steps"].Value = "Text"; //Here is where I would like to add my image

workItem.Fields["Assigned To"].Value = "Assigned";
workItem.Attachments.Add(new Attachment(File, "comment"));
workItem.Save();

For further clarification here is what I am essentially trying to do: enter image description here

enter image description here

enter image description here

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Jhogg
  • 109
  • 1
  • 10

1 Answers1

3

I believe that the Description field is encoded as a variety of HTML and the image is first attached as a separate file. (Historically it was a text field so I cannot find anything saying otherwise)

Here is an example of attaching a file

Community
  • 1
  • 1
Guvante
  • 18,775
  • 1
  • 33
  • 64
  • So I should attach file (Like I did with my other attachments) then reference it somehow in the "workItem.Descpription" command? – Jhogg Mar 18 '13 at 22:02
  • @Jhogg: Yes, I would also use the API to get the `Description` of a work item you manually modified to ensure you have the correct syntax. – Guvante Mar 18 '13 at 23:09
  • I am fairly new at c# (this is literally my first application) do you think you could show me what the command might look like assuming Description is the right syntax? Say I `Attachments.Add("file","Description");` Would it be something like `Description.Add("File");`? – Jhogg Mar 19 '13 at 19:09
  • @Jhogg: I believe description is a string property, so `Description = "File"`. – Guvante Mar 19 '13 at 19:11