I created a project wiki in Azure DevOps
and want to get the wiki markdown pages in my .NET application. When using the link
https://dev.azure.com/company/project/_apis/wiki/wikis/KIS.wiki/pages/News
The markdown gets shown in the browser. When I try to do that in code, I am getting
"Wiki page ‘/News/_apis/connectionData’ could not be found. Ensure that the path of the page is correct and the page exists."
My code looks like this:
var url = new Uri("https://dev.azure.com/company/project/_apis/wiki/wikis/KIS.wiki/pages/News");
var personalAccessToken = "xxxxxxxxxxxxxxxx";
var credentials = new VssCredentials(new VssBasicCredential("", personalAccessToken));
using (var connection = new VssConnection(url, credentials))
{
var wikiClient = connection.GetClient<WikiHttpClient>();
var markdown = wikiClient.GetWikiAsync("KIS.wiki").Result;
}
The error appears on GetClient().
What am I doing wrong?
I see a couple problems with how you're trying to get the page content.
private static string BasePath = $"https://dev.azure.com/{Organization}";
GetWikiAsync(...)
method when you want to be using the GetPageAsync(...)
methodprivate readonly IVssCredentialsFactory _credentialsFactory;
private const string ApiVersion = "5.1";
private static string BasePath = $"https://dev.azure.com/{Organization}";
private const string Organization = "company";
private const string Project = "project";
public AzureRepository(IVssCredentialsFactory credentialsFactory)
{
_credentialsFactory = credentialsFactory;
}
public void GetWikiPage()
{
using (var connection = new VssConnection(new Uri(BasePath), _credentialsFactory.GetCredentials()))
{
var wikiClient = connection.GetClient<WikiHttpClient>();
var wikiId = "KIS.wiki";
var path = "/News";
var page = wikiClient.GetPageAsync(Project, wikiId, path, includeContent : true).Result;
var content = page.Page.Content;
}
}
notes about this sample:
IVssCredentialsFactory
is my creation, so don't look for it in the libYou should look at the c# client samples. It's not exhaustive, but can be helpful.