locked
Show Work Item Attachment in Work Item Description RRS feed

  • Question

  • Hi there,

    I want to display images in Work Item descriptin field. For that I throught I add images as attachment (Field: Attachment) to Work Item.

    In TFS2012 that I use there is a Description field which displays HTML.

    Here I found out that I can insert <a> tags with href param to show clickable links. If I write <img src="..." /> I can display images.

    The image should be displayed like in this tutorial descripted: http://msmvps.com/blogs/vstsblog/archive/2008/08/09/using-images-in-description-fields.aspx

    By adding an image I can not find out which url does a attachment of a work item has that I can directly show it in Work Item Description field.

    Is there a solution for that?



    Thursday, December 5, 2013 9:28 AM

Answers

  • That is a very old blog. TFS 2012 HTML fields support copy/paste. For instance, open Bing home page, right-click and copy any image. Now open a work item with an HTML field, right-click in the field and choose paste. Image inserted.

    Alternately, you will see in the fields toolbar an insert image button. Click it and browse to any image to insert it.


    "You will find a fortune, though it will not be the one you seek." - Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

    Thursday, December 5, 2013 10:10 PM

All replies

  • Hi Hans,

    As suggested in link mentioned by you - that one way to get work item attachment link. double click attachment and copu url from browser. Other way you can get the attachment Url is by using TFS object Model. You can fetch url using TFS API. Here is code you can use  -

    string tfsUrl = "https://yourtfservice:8080/tfs/collection";
    var tcollection = new Uri(tfsUrl);
    //get credentials by logging in with a user interface
    var credentialsProvider = new UICredentialsProvider();
    var teamProjectCollection = new TfsTeamProjectCollection(tcollection, credentialsProvider);
    teamProjectCollection.Authenticate();
    
    var workItemStore = teamProjectCollection.GetService<WorkItemStore>();
     
    var queryresults = workItemStore.Query("Select * From WorkItems Where [Work Item Type] = 'Bug' Order By [State] Asc, [Changed Date] Desc";
     
    string attUrl = string.Empty;
    
    //process all returned workitems
    foreach (WorkItem workItem in queryresults)
     {
        foreach (Attachment attachment in workItem.Attachments)
        {
            attUrl = attachment.Uri.ToString();        
                    
         }
      } 

    The way you are looking for implementation - I tried it at my end and find that you can add image, links directly to description field. Also as you said you can add images but you need Url too. In that case you follow below steps -

    1. Add image to description

    2. Now Select image and Click on Convert to Hyperlink

    3. Add attachment url and Ok

    4. your image will be becomes hyperlink like any other link in description.

    I hope this will help solve your concern. Do let us know if this is not the case


    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    Thursday, December 5, 2013 10:17 AM
  • That is a very old blog. TFS 2012 HTML fields support copy/paste. For instance, open Bing home page, right-click and copy any image. Now open a work item with an HTML field, right-click in the field and choose paste. Image inserted.

    Alternately, you will see in the fields toolbar an insert image button. Click it and browse to any image to insert it.


    "You will find a fortune, though it will not be the one you seek." - Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

    Thursday, December 5, 2013 10:10 PM