I am trying to create update WorkItem through TFS API [C# Code]. My description content is coming from some other system and having inline image embedded [Image as base 64 encoded].
I have noticed that when the image size is smaller near to 30 kb, it is getting updated in the TFS description field and it is showing fine. But when image size is more then 100 kb, it is not showing any content to the WorkItem description. It just writing<img> tag without src attribute.
I have also noticed that it is allowing to set the long base 64 encoded source of image to the description but when we save the workitem with workItem.Save();, the image source gets removed.
Following is the sample program I am running.
using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.Framework.Client; using Microsoft.TeamFoundation.Framework.Common; using Microsoft.TeamFoundation.WorkItemTracking.Client; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Net; using System.Text; namespace TFSTestImage { class Program { static void Main(string[] args) { string serverUrl = "http://tfsserver:8080/tfs"; string userName = "test"; string password = "test"; string teamCollection = "DefaultCollection"; string projectName = "Project1"; int wiId = 5241; TfsConfigurationServer tfsServer = null; NetworkCredential networkCredential = new NetworkCredential(userName, password); Uri tfsUri = new Uri(serverUrl); ICredentials credential = (ICredentials)networkCredential; tfsServer = new TfsConfigurationServer(tfsUri, credential); tfsServer.EnsureAuthenticated(); CatalogNode configurationServerNode = tfsServer.CatalogNode; ReadOnlyCollection<CatalogNode> tpcNodes = configurationServerNode.QueryChildren(new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); TfsTeamProjectCollection tfsTeamProjectCollection = null; foreach (CatalogNode tpcNode in tpcNodes) { if (tpcNode.Resource.DisplayName.Equals(teamCollection)) { tfsTeamProjectCollection = tfsServer.GetTeamProjectCollection(new Guid(tpcNode.Resource.Properties["InstanceID"])); break; } } WorkItemStore wiStore = tfsTeamProjectCollection.GetService<WorkItemStore>(); Project project = wiStore.Projects[projectName]; WorkItem workItem = project.Store.GetWorkItem(wiId); string desc = "<img src=\"data:image/jpeg;base64,{base 64 encoded image data}\" alt=\"\">"; workItem.Fields["Description"].Value = desc; workItem.Save(); Console.WriteLine("Workitem updates successfully !!"); } } }
In the above program for the smaller image encoded data, it is writing image to the description field but for the larger image it is just writing image tag like <img alt=""> and showing empty description on the UI. [Because of the character
limit, I am not able to keep both image encoded data in the example.]
Is there any image size limit while writing from API ? If yes, is it configurable or fixed ?
From UI I am able to copy same image to description and save it.
TFS Instance Details:
Visual Studio Team Foundation Server 2013
Version 12.0.21005.1
Thanks,
Niraj