I am trying to attach a file with TFS test case work item. As first step, I am trying to create the attachment file in TFS attachment store. Once the file is created in the attachment store, I would be getting AttachmentReference object and with that object, I am planning to attach the file with the selected work item with ID 595. But, my process hangs at CreateAttachmentAsync function call. Any help is appreciated!
public void AttachFile(VssConnection connection) { //use the workItemTrackingHttpClient try { using (WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>()) { //create a work item //WorkItem wi = witClient.GetWorkItemAsync(595, expand: WorkItemExpand.All).Result; string filePath = @"C:\Temp\attach-file.PNG"; AttachmentReference attachRef = witClient.CreateAttachmentAsync(filePath, "simple").Result; JsonPatchDocument patchDocument = new JsonPatchDocument(); //add fields to your patch document patchDocument.Add( new JsonPatchOperation() { Operation = Operation.Add, Path = "/relations/-", Value = new { rel = "AttachedFile", url = attachRef.Url, attributes = new { comment = "Adding new attachment for Test Case 2" } } } ); WorkItem result = witClient.UpdateWorkItemAsync(patchDocument, 595).Result; } } catch (Exception ex) { string msg = ex.Message; } }
simple. You shouldn't need to pass it in. Also, that value should be an enum property. Could this be what's hanging you up?