Ejemplo n.º 1
0
        public WorkItem AddAttachment()
        {
            int    id       = Convert.ToInt32(Context.GetValue <WorkItem>("$newWorkItem3").Id);
            string filePath = ClientSampleHelpers.GetSampleTextFile();

            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            // upload attachment to store and get a reference to that file
            AttachmentReference attachmentReference = workItemTrackingClient.CreateAttachmentAsync(filePath).Result;

            JsonPatchDocument patchDocument = new JsonPatchDocument();

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Test,
                Path      = "/rev",
                Value     = "1"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/fields/System.History",
                Value     = "Adding the necessary spec"
            }
                );

            patchDocument.Add(
                new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path      = "/relations/-",
                Value     = new
                {
                    rel        = "AttachedFile",
                    url        = attachmentReference.Url,
                    attributes = new { comment = "VanDelay Industries - Spec" }
                }
            }
                );

            WorkItem result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id).Result;

            return(result);
        }
Ejemplo n.º 2
0
        public AttachmentReference UploadTextFile()
        {
            // Full path to the text file to upload as an attachment
            string filePath = ClientSampleHelpers.GetSampleTextFile();

            // Get a client
            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            Console.WriteLine("Attempting upload of: {0}", filePath);

            // Upload the attachment
            AttachmentReference attachment = workItemTrackingClient.CreateAttachmentAsync(@filePath).Result;

            Console.WriteLine("Attachment created");
            Console.WriteLine(" ID    : {0}", attachment.Id);
            Console.WriteLine(" URL   : {0}", attachment.Url);

            // Save the attachment ID for the "download" sample call later
            Context.SetValue <Guid>("$attachmentId", attachment.Id);
            Context.SetValue <string>("$attachmentFileName", Path.GetFileName(filePath));

            return(attachment);
        }