DCSIMG
TFS API Part 10: Add Area/Iteration Programmatically - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

TFS API Part 10: Add Area/Iteration Programmatically

TFS API Part 10: Add Area/Iteration Programmatically

In my last post I talk about TFS API Part 9: Get Area/Iteration Programmatically.

In this post I will show how to add Area or Iteration programmatically ICommonStructureService.

image

First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll,Microsoft.TeamFoundation.WorkItemTracking.Client.dll
located in - C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Server;

using Microsoft.TeamFoundation.Client;

Download Demo

If the Node not exists checking if there is more then one Area/Iteration to create
(Example: Area 7\\Sub Area 7)

 

int BackSlashIndex = ElementPath.LastIndexOf("\\");

string Newpathname = ElementPath.Substring(BackSlashIndex + 1);

string NewPath = (BackSlashIndex == 0 ? string.Empty : ElementPath.Substring(0, BackSlashIndex));

string PathRoot = rootNodePath + NewPath;

NodeInfo previousPath = null;

try

{

    previousPath = css.GetNodeFromPath(PathRoot);

}

catch (Exception ex)

{

    if (ex.Message.Contains("Invalid path."))

    {

        //just means that this path is not exist and we can continue.

        previousPath = null;

    }

    else

    {

        throw ex;

    }

}

if (previousPath == null)

{

    //call this method to create the parent paths.

    previousPath = AddNode(NewPath, projectName, nodeType);

}

string newPathUri = css.CreateNode(Newpathname, previousPath.Uri);

return css.GetNode(newPathUri);

 

image

Checking if the Node exists…

NodeInfo retVal;

string rootNodePath = "\\" + projectName + "\\" + nodeType.ToString();

 

//Check if this path already exsist

string newPath = rootNodePath + ElementPath;

try

{

    retVal = css.GetNodeFromPath(newPath);

    if (retVal != null)

    {

        return null; //already exists

    }

}

catch (Exception ex)

{

    if (ex.Message.Contains("The following node does not exist"))

    {

        //just means that this path is not exist and we can continue.

    }

    else

    {

        throw ex;

    }

}

 

image

Download Demo

 

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# January 31, 2009 1:24 AM

Shai Raiten said:

TFS API Summary & My #200 Post It’s been 4 months, 3 weeks(143 days) since my ..::: My #100 Post

# February 13, 2009 11:44 PM

jampick's WebLog said:

I recently had to create an area tree, in a TFS project, with  large number (500+) of nodes. 

# June 7, 2009 12:48 AM

Bulk update of TFS Areas with ICommonStructureService | Coded Style said:

Pingback from  Bulk update of TFS Areas with ICommonStructureService | Coded Style

# June 7, 2009 2:52 AM

Bulk update of TFS Areas with ICommonStructureService | Coded Style said:

Pingback from  Bulk update of TFS Areas with ICommonStructureService | Coded Style

# June 7, 2009 2:52 AM

Bulk update of TFS Areas with ICommonStructureService | Coded Style said:

Pingback from  Bulk update of TFS Areas with ICommonStructureService | Coded Style

# June 7, 2009 2:52 AM

Tune Up Your PC » Post Topic » Bulk update of TFS Areas with ICommonStructureService said:

Pingback from  Tune Up Your PC  » Post Topic   » Bulk update of TFS Areas with ICommonStructureService

# June 7, 2009 5:07 PM

Bulk update of TFS Areas with ICommonStructureService | Coded Style said:

Pingback from  Bulk update of TFS Areas with ICommonStructureService | Coded Style

# August 10, 2009 3:12 PM

Bulk update of TFS Areas with ICommonStructureService | Coded Style said:

Pingback from  Bulk update of TFS Areas with ICommonStructureService | Coded Style

# August 10, 2009 3:12 PM

Leo said:

Very nice!

# March 7, 2010 9:02 AM

Programmatically add new iteration in TFS - Programmers Goodies said:

Pingback from  Programmatically add new iteration in TFS - Programmers Goodies

# October 3, 2011 3:20 AM

Programmatically add new iteration in TFS - Programmers Goodies said:

Pingback from  Programmatically add new iteration in TFS - Programmers Goodies

# October 3, 2011 3:20 AM

ezien said:

IF you also want to see the area/iteration node permissions, this post contains the code you need:

ezien.com/.../tfs-api-get-area-or-iteration-permissions

# May 8, 2012 11:54 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: