-1

I have a .xlsx file, which contains the first column projectname, second column description. I want to create a console app for create projects from azureProjects.xlsx file using Azure DevOps Rest API. I already implement the code below, but I can't understand how to read from .xlsx file and implement the code. Can you have a solution to help me?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

   namespace WorkItemTest
   {
class AzureAdmin
{
    private readonly Uri uri;
    private readonly string personalAccessToken;

    public AzureAdmin(string orgName, string personalAccessToken)
    {
        this.uri = new Uri("https://dev.azure.com/" + orgName);
        this.personalAccessToken = personalAccessToken;
    }

    public async Task<bool> createProject()
    {

        try
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                    Convert.ToBase64String(
                        Encoding.ASCII.GetBytes(
                            string.Format("{0}:{1}", "", personalAccessToken))));

                var req = new Root
                {
                    name = "test3",
                    description = "test about smthng",
                    visibility = 0,
                    capabilities = new Capabilities
                    {
                        versioncontrol = new Versioncontrol {sourceControlType = "Git"},
                        processTemplate = new ProcessTemplate
                        {
                            templateTypeId = "b8a3a935-7e91-48b8-a94c-606d37c3e9f2"
                        }
                    }
                };

                var result = await client.PostAsJsonAsync($"{uri}/_apis/projects?api-version=5.1", req); //
                Console.WriteLine(result.StatusCode);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        return true;
    }

    public class Versioncontrol
    {
        public string sourceControlType { get; set; }
    }

    public class ProcessTemplate
    {
        public string templateTypeId { get; set; }
    }

    public class Capabilities
    {
        public Versioncontrol versioncontrol { get; set; }
        public ProcessTemplate processTemplate { get; set; }
    }

    public class Root
    {
        public string name { get; set; }
        public string description { get; set; }
        public int visibility { get; set; }
        public Capabilities capabilities { get; set; }
    }

 }
}
bigOteta
  • 1
  • 1

1 Answers1

0

You have implemented how to create a team project in DevOps, what you need is reading the project names from .xlsx file. This is not implemented via Azure Devops API, you just need to get help from Excel side to get how to read data from .xlsx file via api.

Check the following link to see whether it helps you:

https://learn.microsoft.com/en-us/troubleshoot/dotnet/csharp/query-excel-data-aspx-page

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39