Locked Open Work Item in Team Web Access from C# Code

  • Tuesday, May 31, 2011 4:26 PM
     
      Has Code
    Steps:
    1. Connect
     
    I have created a Work Item in TFS in C# code and now I would like to open that same Work Item in Team Web Access. Can anyone point me in the right direction?
    Steps:
    1. Connect to a Team Project in TFS using the TeamProjectPicker Dialog in C#
    2. Create a work item with a title and save it
    3. Open the newly created work item in Team Web Access so the user can contiue editing it ( - I don't know how to do this).
    Here is the code I have currently
        private void PickTFSProject()
        {
          TeamProjectPicker pp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
    
          pp.ShowDialog();
    
          if (pp.SelectedTeamProjectCollection == null)
          {
            throw new Exception("Nothing selected");
          }
          pp.SelectedTeamProjectCollection.EnsureAuthenticated();
          tfsProjectCollection = pp.SelectedTeamProjectCollection;
          store = (WorkItemStore)tfsProjectCollection.GetService(typeof(WorkItemStore));
    
          
          tfsproject = store.Projects[pp.SelectedProjects[0].Name];
        }
    
        private void CreateWorkItem(string wiType)
        {
          WorkItem pbiWI = new WorkItem(tfsproject.WorkItemTypes[wiType]);
          pbiWI.Title = "Test title";
          pbiWI.Save();
          
        }
    
    Thanks,
    Gunnar Thorsteinsson
     

    Project Manager LS Retail, PMP

All Replies

  • Thursday, June 02, 2011 9:19 AM
    Moderator
     
     

    Hi Gunnar,

     

    Thanks for your post.

     

    Do you mean that you created a new Work Item using TFS API, then you want to find this new Work Item in Team Web Access and continue to edit it(manually)?

     

    For how to get work items in Team Web Access, please refer to: http://msdn.microsoft.com/en-us/library/ee523998.aspx.

     

    After pbiWI.Save(), I think you can get this new Work Item’s ID like: pbiWI.Id. Then get this work item in Team Web Access using ID directly.


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Monday, June 06, 2011 6:58 AM
    Moderator
     
     

    Hi Gunnar,

     

    What about the progress for this issue?


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Monday, June 06, 2011 3:20 PM
     
      Has Code

    Hello John and thank you for your answer,

     

    I am able to open my Work Item in Team Web access using the code

        private void CreateWorkItem(string wiType)
        {
          WorkItem pbiWI = new WorkItem(tfsproject.WorkItemTypes[wiType]);
          pbiWI.Title = "Test title";
          pbiWI.Save();
          GotoWI(pbiWI.Id);
          pbiWI.Close();
        }
    
        private void GotoWI(int wiID)
        {
          string myUrl = @"https://<SERVER NAME>:<SERVER PORT>/tfs/web/wi.aspx?id=" + wiID.ToString();
          System.Diagnostics.Process.Start(myUrl);
        }
    

    I am able to hard code my <SERVER NAME>:<SERVER PORT> but do you know if I can get the URL to the work item programmatically?

     

    Best regards,

    Gunnar 


    Project Manager LS Retail, PMP
  • Tuesday, June 07, 2011 6:39 AM
    Moderator
     
     Answered

    Hi Gunnar,

     

    Thanks for your reply.

     

    As far as I know, the Work Item page URL address in Team Web Access is: http://servername:port/tfs/web/UI/Pages/WorkItems/WorkItemEdit.aspx?id=id&pguid=TeamProjectGUID. For example: http://servername:8080/tfs/web/UI/Pages/WorkItems/WorkItemEdit.aspx?id=1&pguid=ea844cc1-e08e-49f3-baeb-9e554519e473. Please try this.

     

    You can find Team Project’s Guid in Team Explorer, selected Team Project, check Team Project’s Url in Properties windows, it should be: vstfs:///Classification/TeamProject/guid.


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Wednesday, June 08, 2011 10:09 AM
    Moderator
     
     

    Hi Gunnar,

     

    Have you tried that?


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Wednesday, May 16, 2012 9:01 PM
     
      Has Code

    Here is what I am doing:

    		private void OpenWorkItem(WorkItem wi)
    		{
    			const string workItemUrl = @"{0}://{1}:{2}/tfs/web/wi.aspx?id={3}";
    			string scheme = wi.Store.TeamProjectCollection.Uri.Scheme;
    			string server = wi.Store.TeamProjectCollection.Uri.Host;
    			int port = wi.Store.TeamProjectCollection.Uri.Port;
     
    			string url = string.Format(workItemUrl, scheme, server, port, wi.Id);
    			System.Diagnostics.Process.Start(url);
    		}