This is another post in the series “how to export Work Item data to Word Document".
Complete code for project can be found in GitHub - https://github.com/alkampfergit/AzureDevopsWordPlayground
Post in the series:
- API Connection
- Retrieve Work Items Information
- Azure DevOps API, Embed images into HTML
- Create Word Document For Work Items
- Retrieve image in Work Item Description with TFS API
- Retrieve Attachment in Azure DevOps with REST API in C#
Exporter project was updated a little bit in past months, I had no time for blogging about it but probably it is the time to give further information on how to export all of your Work Items to a Word File.
First of all I’ve introduced a new template syntax that allows for more complex export, as an example suppose you want to create a release note composed by an header followed by a ì list of PBIs then list of all Bugs both filtered to specific iteration.
Let’s start examining folder with the template, located at this address. If you look at the content there are some word files then a special file called structure.txt that contains the structure of the template.
This file has a special syntax that allows inclusion of static word files and a series of queries to create a structured document. A special Parameters section allows the specification of parameters that will be used on queries to parametrize your export. Paramters are supposed to be supplied by the user to create an export.
The purpose of the structure file is to create a definition of the structure of final document, then the composer will execute the query and generate complete file.
With this structure file you can call command line version of the software to immediately create word files without user interaction. This is a sample command line.
The only peculiar parameter is the –tokenfile that allows you to specify a file that contains plain text Personal Access Token. Since my disk is usually encrypted by BitLocker I can tolerate having a file with a valid PAT in my disk. This will immediately starts a console application that will create word file, you have some log that allows you to understand what is going on and finally the resulting word file is opened.
Figure 1: Export in action
If you prefer an interactive approach, a really ugly User Interface is present that allows for a richer interaction. The UI is still really beta, but it allow you to interactively connect to your server and run an export.
Figure 2: Word exporter ui
I know that the UI is ugly, but at least you an interactively
- Specify your server and connect, it will ask you for credentials
- Choose a team project
- Specify the folder that contains all templates
- Select one of the template
- Have a stupid UI to populate template parameters
- Press a button and generate the export
In this last version I’ve also made some fixes: especially for image retrieval. The problem with image as attachment is that if you are on-premise you have probably a Network Credentials, while if you are in Azure DevOps you have a completely different set of credentials. A special method check if the current _tfsCollection has a NetworkCredentials with a valid UserName, if not it will return null.
Now depending on the result of the above method, we can choose to retrieve the image with NeworkCredential, or use API otherwise.
This is needed to handle both on-premise TFS (azure devops server) and Azure DevOps standard accounts. Probably using the API for both environment could be a solution, for this version I prefer using a direct Network call for on-premise installation.
Another noticeable fix is checking for real WorkItem field type to correctly identify all html field (acceptance criteria, etc) and correctly create an HtmlSubstitution to generate a Word with formatted HTML content. I’ve also fixed content encoding to avoid weird chars in HTML content.
Given these two fixes this little utils is now ready to be used to export Work Item data in a nice Formatted Word file.