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.

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);
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;
}
}
Download Demo