none
TFS 2010 - Bulk Update all Work Item HyperLinks

    Question

  • I have just migrated from TFS 2008 to TFS 2010. As part of the migration Sharepoint is now located on a different server. This means that none of the Work Item hyperlinks that point to the Sharepoint documents are working anymore.

    So I just want to update all these hyperlinks to point at the new Sharepoint server. If I knew where the http addresses were kept in the TFS database I would just update them with some very simple SQL.

    Does anyone know where to find the hyperlinks in the TFS 2010 database? Alternatively does anyone have another method for achieving this (e.g. Powershell).

    Thanks.

    Friday, September 24, 2010 6:15 AM

Answers

  • Hi dezdez,

    writing directly to the TFS databases is not recommended by Microsoft and you should not do it. Consider using a domain name instead of linking directly to computer names to avoid having to deal with issues like this. To solve the problem you can use the TFS API to loop through your work items, replacing existing hyperlinks matching the pattern. This will affect the history of your work items. For information on how to do this have a look at: http://msdn.microsoft.com/en-us/library/bb130347.aspx

    Let me know if you need any more help.

     

     

     

     

     

     

    Friday, September 24, 2010 4:03 PM
  • hi~~~

    Below the sample that work item's hyperlink change with TFS API.

    If you need only ot change the IP, use String.Replace method.

    To connect to TFS and get WorkItemStore object are to check above Gustav's Link(http://msdn.microsoft.com/en-us/library/bb130347.aspx ).

    WorkItemCollection hyperWic = this.workitemStore.Query("select [system.id] from workitems where [System.HyperLinkCount] > 0");
    foreach (WorkItem wi in hyperWic)
    {
     foreach (Link link in wi.Links)
     {
     if (link.BaseType == BaseLinkType.Hyperlink)
     {
      Hyperlink hyper = (Hyperlink)link;
      if (hyper.Location.Contains("http://oldUrl"))
      {
      string comment = hyper.Comment;
    
      wi.Open();
      wi.Links.Remove(hyper);
    
      Hyperlink newHyper = new Hyperlink("http://newUrl");
      newHyper.Comment = comment;
      wi.Links.Add(newHyper);
      wi.Save();
      }
     }
     }
    }
    
    Tuesday, September 28, 2010 7:03 AM

All replies

  • Hi dezdez,

    writing directly to the TFS databases is not recommended by Microsoft and you should not do it. Consider using a domain name instead of linking directly to computer names to avoid having to deal with issues like this. To solve the problem you can use the TFS API to loop through your work items, replacing existing hyperlinks matching the pattern. This will affect the history of your work items. For information on how to do this have a look at: http://msdn.microsoft.com/en-us/library/bb130347.aspx

    Let me know if you need any more help.

     

     

     

     

     

     

    Friday, September 24, 2010 4:03 PM
  • hi~~~

    Below the sample that work item's hyperlink change with TFS API.

    If you need only ot change the IP, use String.Replace method.

    To connect to TFS and get WorkItemStore object are to check above Gustav's Link(http://msdn.microsoft.com/en-us/library/bb130347.aspx ).

    WorkItemCollection hyperWic = this.workitemStore.Query("select [system.id] from workitems where [System.HyperLinkCount] > 0");
    foreach (WorkItem wi in hyperWic)
    {
     foreach (Link link in wi.Links)
     {
     if (link.BaseType == BaseLinkType.Hyperlink)
     {
      Hyperlink hyper = (Hyperlink)link;
      if (hyper.Location.Contains("http://oldUrl"))
      {
      string comment = hyper.Comment;
    
      wi.Open();
      wi.Links.Remove(hyper);
    
      Hyperlink newHyper = new Hyperlink("http://newUrl");
      newHyper.Comment = comment;
      wi.Links.Add(newHyper);
      wi.Save();
      }
     }
     }
    }
    
    Tuesday, September 28, 2010 7:03 AM
  • Hi Park ,

     

    Can u pls help me to write code for link work items

    My problem is

    I need code in C# or ADO.net to create link between work items in TFS 2010

    Please have a look at this block first to get an idea...

    http://blogs.microsoft.co.il/blogs/shair/archive/2010/02/27/tfs-api-part-22-create-link-between-work-item-parent-child-etc.aspx



    Same as above I need code for create link between work items.

    1. I have FPS work items separately in TFS (Without linking to BUC)
    2. I have BUC work items separately in TFS (Without linking to FPS).
    3. I am also going to create two tables in SQL , one for FPS and another one for BUC
    4. FPS table fileds are - ID, Title
    5. BUC table fields are - ID, title and Comments
    6. FPS and BUC table can have more than 20000 records !!!
    7. Then I can write code as follows using C#

    Open TFS server
    Open and Read SQL tables FPS, BUC
    Read first record in FPS , BUC table
    Until end of SQL _FPS, BUC table
    {
    Int A = Find work item in TFS
    Where work item. Identifier =SQL_table_FPS.ID;

    Int B= Find work item in TFS
    Where work item. Identifier= SQL_table_BUC.ID

    Create link between A and B ; link type= satisfies ; Link comments= SQL_Table_BUC.comments;

    Read next record on SQl_table_ FPS, BUC
    }

    Save all in TFS

    End

    Can anybody helpout on this?

    Wednesday, September 29, 2010 1:15 PM
  • Hi~~~

    I can understand what exctly you want.

    do you just want to create a link between seperate two work items?

    hm...Although I doubt this sample is helpful, I attach some code that I have developed in the old time for our application.

    I hope it helpful.

    public void EditLinkType(WorkItem orgWorkItem, WorkItem copyWorkItem)
    {
     orgWorkItem.SyncToLatest();
     // Delete Existing Link
     LinkCollection links = orgWorkItem.Links;
     foreach (Link link in links)
     {
      if (link.BaseType == BaseLinkType.RelatedLink)
      {
       if (((RelatedLink)link).LinkTypeEnd.Name == "Related")
       {
        if (((RelatedLink)link).RelatedWorkItemId == copyWorkItem.Id)
        {
         links.Remove(link);
         break;
        }
       }
      }
     }
    
     // Create New Link Type
     WorkItemLinkType type = this.WorkItemStore.WorkItemLinkTypes["TheOne.TeamCSRLinkType"];
     WorkItemLink wi = new WorkItemLink(type.ReverseEnd, copyWorkItem.Id, orgWorkItem.Id);
     orgWorkItem.Links.Add(wi);
     orgWorkItem.Save();
    }
    

     

    Thursday, September 30, 2010 12:41 AM
  • Hi All,

     

    Thanks for your replies.

     

    • I am using TFS 2010.
    • I have two queries ;the name of the queries are FPS and BUC.
    • FPS query  has 7000 work items and BUC query  has around 9000 work items.
    • FPS and BUC need to be linked as dependency ( satisfies/ Is Satisfied by)
    • Of course , It is hard to link  FPS and BUc manually - it is a 6 months full time job.
    • So , I need code to link them
    • Also I have a two access tables
    • First table has all wok item IDs which belongs to FPS - in order - Eg : Table 1
    • Second table  has all BUC work item IDs and linking comments - In order - Table 2
    • now I need coding for following step

    Connect to TFS

     

    Read table1 , table 2

    Untill end of table1 ,table 2

    A= table 1 .ID

    B= Table2.ID

    c= Table2.comment

    Find work item in TFS where work item.ID == A

    Find work item in TFS where work item.ID == B

    Link work item A & B ;

    Link. omment= C;

    Save ()

    Read next table1 ,table 2;

     

    As above if click the button it should link all FPS and BUC work items.

    Any body help me out on this?

     

     

     

    Thursday, September 30, 2010 1:10 PM
  • how do you get the information A must be linked with B?

    Does table 1 have BUC's ID too? Or any other column that represent two id's relation?

    I guess you can do it if use above my sample and MSDN sample (http://msdn.microsoft.com/en-us/library/bb130323.aspx).

     

    1. Connect TFS and get WorkItemStore object. (reference MSDN)

    2. For loop table1 and find row of table2 per each table1'row.

    3. In loop, Get A(FPS id), B(BUC id),  C(link comment) and then get FPS&BUC work items by A, B.

    4. Create link using below sample.

    // Create New Link Work Item
    WorkItemLinkType type = yourWorkItemStore.WorkItemLinkTypes["System.LinkTypes.Dependency"];
    WorkItemLink link = new WorkItemLink(type.ReverseEnd, B, A);

    link.Comment = C;
     AWorkItem.Links.Add(BWorkItem);
     AWorkItem.Save();

     

    I wanna post full code but to try may be helpful for you.

    Good luck~~

     

     

     

    Thursday, September 30, 2010 11:57 PM
  • Can u please send me the full code ?

    Please

    Friday, October 01, 2010 4:22 AM
  • Hi Park,

    Instead of table ,we can use three text files.

    File 1 - FPS IDs

    File 2- BUC IDs

    File 3 - Comments

     Or we can write all above details in one single file.

    Please send me the full code

     

    Friday, October 01, 2010 4:24 AM
  • Dear Park,

     

    Please forget about all prevoius stuff. please see below what I need.

    I have an excel sheet. It has following columns

    FPS type -
    FPS identifier-
    BUC Type -
    BUC identifier-
    Comments
     
    I used above excel sheet to create work items. Also I have created two queries.
    1. FPS query
    2. BUC query

    FPS query  work item fileds are-  ID, Work item type , Identifier,assign to, title.
    BUC query work item fields are- ID , work item type,identifier,assign to , titile.

    now I need code according below logic to link FPS and BUC work items.


    Read the excel sheet    // we can copy all in to txt file as well instead of excel sheet.
    Read the first row excel sheet;

      end of file = false
     {

    int A= get work item ,

    Where workitem.identifier= excel sheet.FPS identifier; // basically take the value from FPS dentifier coulmnn in the excel sheet

    int B= get  work item
    where work item.identifier= execl sheet.BUCidentifier; // basically take the value from BUC dentifier coulmnn in the excel sheet

    link A & B  // links both work items
    link.comment= Excel.Comments;   // basically take the value from comments coulmnn in the excel sheet;which is use to add comments for links
    Save();

    Can u please write full coding for this.( Assume I can copy all deials in the excel sheet to txt file ,if you want to get all details from txt fiel)

     

    I am waiting for your reply mate

     

    Many Thanks 

    Friday, October 01, 2010 11:09 PM
  • I tried this method - it works for the first work item but immediately after the wi.Save and exception occurs : "operation is not valid due to the state of the object" and subsequent iterations of the loop don't occur.  Any ideas what may be causing this?  I verified this happens only if there is a work item with more than one URL that needs changing.
    Thursday, September 06, 2012 11:14 AM
  • I investigated this and found that the foreach loop in C# does not allow changes to the Collection object it is iterating.  The workaround for the issue is to use a For loop:

    If you have multiple URLs that need modification you could use the following code:

      for (int linkCount = 0; linkCount < wi.Links.Count; linkCount++ )
      {
       Link link = wi.Links[linkCount];
       if (link.BaseType == BaseLinkType.Hyperlink)
       {
          Hyperlink hyper = (Hyperlink)link; if (hyper.Location.Contains("http://oldUrl"))  
          {
             string comment = hyper.Comment; wi.Open(); wi.Links.Remove(hyper);      
             Hyperlink newHyper = new Hyperlink("http://newUrl");
             newHyper.Comment = comment;
             wi.Links.Add(newHyper);
             wi.Save();
          }
       }
      }

             


    • Edited by Sina.Jazayeri Friday, September 07, 2012 12:06 PM improved layout
    • Proposed as answer by Sina.Jazayeri Friday, September 07, 2012 12:07 PM
    Friday, September 07, 2012 11:59 AM