Search code examples
c#githuboctokit.net

How to download a file from private repo using c# octokit


How to download a file from a private repo using c# octokit Thanks


Solution

  • For more information: Octokit.net Documentation

            var gitHubClient = new GitHubClient(new ProductHeaderValue("app-name"));
            var credentials = new Credentials(token: "your-token");
            gitHubClient.Credentials = credentials;
    
            var repositoryContents =
                await gitHubClient.Repository.Content.GetAllContents("owner", "repo-name");
            var firstOrDefault = repositoryContents.FirstOrDefault(c => c.Path == @"path-of-the-file-you-want");
            var downloadUrl = firstOrDefault?.DownloadUrl;
    

    Then you can download this file with the download url.