How to create a bug in TFS Programmatically









up vote
0
down vote

favorite












Am looking for a small code snippet which helps me to create a defect in TFS Programmatically using c# VSTS2015.



My TFS Server: http://tfs2.dell.com:8080/tfs/eDell/eDellPrograms/
server is: http://tfs2.dell.com:8080/tfs
Collection is: eDell
Project is: eDellPrograms



Work Item = Defect



Thanks,
Satish D










share|improve this question





















  • Why are you trying to do this?
    – Yair Halberstadt
    Nov 11 at 11:48














up vote
0
down vote

favorite












Am looking for a small code snippet which helps me to create a defect in TFS Programmatically using c# VSTS2015.



My TFS Server: http://tfs2.dell.com:8080/tfs/eDell/eDellPrograms/
server is: http://tfs2.dell.com:8080/tfs
Collection is: eDell
Project is: eDellPrograms



Work Item = Defect



Thanks,
Satish D










share|improve this question





















  • Why are you trying to do this?
    – Yair Halberstadt
    Nov 11 at 11:48












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Am looking for a small code snippet which helps me to create a defect in TFS Programmatically using c# VSTS2015.



My TFS Server: http://tfs2.dell.com:8080/tfs/eDell/eDellPrograms/
server is: http://tfs2.dell.com:8080/tfs
Collection is: eDell
Project is: eDellPrograms



Work Item = Defect



Thanks,
Satish D










share|improve this question













Am looking for a small code snippet which helps me to create a defect in TFS Programmatically using c# VSTS2015.



My TFS Server: http://tfs2.dell.com:8080/tfs/eDell/eDellPrograms/
server is: http://tfs2.dell.com:8080/tfs
Collection is: eDell
Project is: eDellPrograms



Work Item = Defect



Thanks,
Satish D







c# api tfs tfs2012 defects






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 10:44









Satish Dhanaraj

2819




2819











  • Why are you trying to do this?
    – Yair Halberstadt
    Nov 11 at 11:48
















  • Why are you trying to do this?
    – Yair Halberstadt
    Nov 11 at 11:48















Why are you trying to do this?
– Yair Halberstadt
Nov 11 at 11:48




Why are you trying to do this?
– Yair Halberstadt
Nov 11 at 11:48












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You have 2 options:



  1. TFS Soap API (SDK)

  2. TFS Rest API

For TFS Soap API (SDK) you need these DLL's:



Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.WorkItemTracking.Client;


The code is:



using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace createNewWorkItem

class Program

static int Main(string args)

Uri collectionUri = new Uri("http://server:8080/TFS/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["MyProject"];
WorkItemType workItemType = teamProject.WorkItemTypes["Defect"];

WorkItem Defect = new WorkItem(workItemType);

Defect.Title = "TITLE GOES HERE";
Defect.Description = "DESCRIPTION GOES HERE";
Defect.Fields["Issue ID"].Value = "999999";


Defect.Save();
return (Defect.Id);







If you want use Rest API you don't need the above DLL's.



The code is:



 public static async void createtWorkItem()

string requestUrl = "http://TFS2015servername:8080/tfs/collectionname/teamprojectname/_apis/wit/workitems/$Defect?api-version=1.0";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(new objectnew

op = "add",
path = "/fields/System.Title",
value = "New Task from TFS 2015 REST API"
);

HttpClientHandler authtHandler = new HttpClientHandler()

// Credentials = CredentialCache.DefaultNetworkCredentials
Credentials = new NetworkCredential("username", "password", "domainname")
;

using (HttpClient client = new HttpClient(authtHandler))

var method = new HttpMethod("PATCH");

var request = new HttpRequestMessage(method, requestUrl)

Content = new StringContent(json, Encoding.UTF8,
"application/json-patch+json")
;
HttpResponseMessage hrm = await client.SendAsync(request);

Console.WriteLine("Completed!");
;






share|improve this answer




















  • Thank you @Shayki Abramczyk.... the Option1 helped me....
    – Satish Dhanaraj
    Nov 13 at 11:03










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247955%2fhow-to-create-a-bug-in-tfs-programmatically%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You have 2 options:



  1. TFS Soap API (SDK)

  2. TFS Rest API

For TFS Soap API (SDK) you need these DLL's:



Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.WorkItemTracking.Client;


The code is:



using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace createNewWorkItem

class Program

static int Main(string args)

Uri collectionUri = new Uri("http://server:8080/TFS/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["MyProject"];
WorkItemType workItemType = teamProject.WorkItemTypes["Defect"];

WorkItem Defect = new WorkItem(workItemType);

Defect.Title = "TITLE GOES HERE";
Defect.Description = "DESCRIPTION GOES HERE";
Defect.Fields["Issue ID"].Value = "999999";


Defect.Save();
return (Defect.Id);







If you want use Rest API you don't need the above DLL's.



The code is:



 public static async void createtWorkItem()

string requestUrl = "http://TFS2015servername:8080/tfs/collectionname/teamprojectname/_apis/wit/workitems/$Defect?api-version=1.0";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(new objectnew

op = "add",
path = "/fields/System.Title",
value = "New Task from TFS 2015 REST API"
);

HttpClientHandler authtHandler = new HttpClientHandler()

// Credentials = CredentialCache.DefaultNetworkCredentials
Credentials = new NetworkCredential("username", "password", "domainname")
;

using (HttpClient client = new HttpClient(authtHandler))

var method = new HttpMethod("PATCH");

var request = new HttpRequestMessage(method, requestUrl)

Content = new StringContent(json, Encoding.UTF8,
"application/json-patch+json")
;
HttpResponseMessage hrm = await client.SendAsync(request);

Console.WriteLine("Completed!");
;






share|improve this answer




















  • Thank you @Shayki Abramczyk.... the Option1 helped me....
    – Satish Dhanaraj
    Nov 13 at 11:03














up vote
0
down vote



accepted










You have 2 options:



  1. TFS Soap API (SDK)

  2. TFS Rest API

For TFS Soap API (SDK) you need these DLL's:



Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.WorkItemTracking.Client;


The code is:



using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace createNewWorkItem

class Program

static int Main(string args)

Uri collectionUri = new Uri("http://server:8080/TFS/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["MyProject"];
WorkItemType workItemType = teamProject.WorkItemTypes["Defect"];

WorkItem Defect = new WorkItem(workItemType);

Defect.Title = "TITLE GOES HERE";
Defect.Description = "DESCRIPTION GOES HERE";
Defect.Fields["Issue ID"].Value = "999999";


Defect.Save();
return (Defect.Id);







If you want use Rest API you don't need the above DLL's.



The code is:



 public static async void createtWorkItem()

string requestUrl = "http://TFS2015servername:8080/tfs/collectionname/teamprojectname/_apis/wit/workitems/$Defect?api-version=1.0";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(new objectnew

op = "add",
path = "/fields/System.Title",
value = "New Task from TFS 2015 REST API"
);

HttpClientHandler authtHandler = new HttpClientHandler()

// Credentials = CredentialCache.DefaultNetworkCredentials
Credentials = new NetworkCredential("username", "password", "domainname")
;

using (HttpClient client = new HttpClient(authtHandler))

var method = new HttpMethod("PATCH");

var request = new HttpRequestMessage(method, requestUrl)

Content = new StringContent(json, Encoding.UTF8,
"application/json-patch+json")
;
HttpResponseMessage hrm = await client.SendAsync(request);

Console.WriteLine("Completed!");
;






share|improve this answer




















  • Thank you @Shayki Abramczyk.... the Option1 helped me....
    – Satish Dhanaraj
    Nov 13 at 11:03












up vote
0
down vote



accepted







up vote
0
down vote



accepted






You have 2 options:



  1. TFS Soap API (SDK)

  2. TFS Rest API

For TFS Soap API (SDK) you need these DLL's:



Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.WorkItemTracking.Client;


The code is:



using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace createNewWorkItem

class Program

static int Main(string args)

Uri collectionUri = new Uri("http://server:8080/TFS/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["MyProject"];
WorkItemType workItemType = teamProject.WorkItemTypes["Defect"];

WorkItem Defect = new WorkItem(workItemType);

Defect.Title = "TITLE GOES HERE";
Defect.Description = "DESCRIPTION GOES HERE";
Defect.Fields["Issue ID"].Value = "999999";


Defect.Save();
return (Defect.Id);







If you want use Rest API you don't need the above DLL's.



The code is:



 public static async void createtWorkItem()

string requestUrl = "http://TFS2015servername:8080/tfs/collectionname/teamprojectname/_apis/wit/workitems/$Defect?api-version=1.0";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(new objectnew

op = "add",
path = "/fields/System.Title",
value = "New Task from TFS 2015 REST API"
);

HttpClientHandler authtHandler = new HttpClientHandler()

// Credentials = CredentialCache.DefaultNetworkCredentials
Credentials = new NetworkCredential("username", "password", "domainname")
;

using (HttpClient client = new HttpClient(authtHandler))

var method = new HttpMethod("PATCH");

var request = new HttpRequestMessage(method, requestUrl)

Content = new StringContent(json, Encoding.UTF8,
"application/json-patch+json")
;
HttpResponseMessage hrm = await client.SendAsync(request);

Console.WriteLine("Completed!");
;






share|improve this answer












You have 2 options:



  1. TFS Soap API (SDK)

  2. TFS Rest API

For TFS Soap API (SDK) you need these DLL's:



Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.WorkItemTracking.Client;


The code is:



using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace createNewWorkItem

class Program

static int Main(string args)

Uri collectionUri = new Uri("http://server:8080/TFS/");
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects["MyProject"];
WorkItemType workItemType = teamProject.WorkItemTypes["Defect"];

WorkItem Defect = new WorkItem(workItemType);

Defect.Title = "TITLE GOES HERE";
Defect.Description = "DESCRIPTION GOES HERE";
Defect.Fields["Issue ID"].Value = "999999";


Defect.Save();
return (Defect.Id);







If you want use Rest API you don't need the above DLL's.



The code is:



 public static async void createtWorkItem()

string requestUrl = "http://TFS2015servername:8080/tfs/collectionname/teamprojectname/_apis/wit/workitems/$Defect?api-version=1.0";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(new objectnew

op = "add",
path = "/fields/System.Title",
value = "New Task from TFS 2015 REST API"
);

HttpClientHandler authtHandler = new HttpClientHandler()

// Credentials = CredentialCache.DefaultNetworkCredentials
Credentials = new NetworkCredential("username", "password", "domainname")
;

using (HttpClient client = new HttpClient(authtHandler))

var method = new HttpMethod("PATCH");

var request = new HttpRequestMessage(method, requestUrl)

Content = new StringContent(json, Encoding.UTF8,
"application/json-patch+json")
;
HttpResponseMessage hrm = await client.SendAsync(request);

Console.WriteLine("Completed!");
;







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 13:01









Shayki Abramczyk

2,5071621




2,5071621











  • Thank you @Shayki Abramczyk.... the Option1 helped me....
    – Satish Dhanaraj
    Nov 13 at 11:03
















  • Thank you @Shayki Abramczyk.... the Option1 helped me....
    – Satish Dhanaraj
    Nov 13 at 11:03















Thank you @Shayki Abramczyk.... the Option1 helped me....
– Satish Dhanaraj
Nov 13 at 11:03




Thank you @Shayki Abramczyk.... the Option1 helped me....
– Satish Dhanaraj
Nov 13 at 11:03

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247955%2fhow-to-create-a-bug-in-tfs-programmatically%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3