Search code examples
tfsazure-devopsazure-devops-rest-apiazure-devops-server-2019

How can I retrieve a list of Azure DevOps Wiki pages to be able to edit them?


I'm using the .NET client API to access our Azure DevOps server.

How can I retrieve a list of Wiki pages, so I can edit their content and store the changes then?

Here's what I got so far:

using (WikiHttpClient client = new WikiHttpClient(App.ProjectUrl, new VssCredentials()))
{
    using (Stream s = await client.GetPageTextAsync(ConfigurationManager.AppSettings["RepositoryContext"], ConfigurationManager.AppSettings["WikiPageName"]))
    using (StreamReader sr = new StreamReader(s))
    {
        string text = sr.ReadToEnd();
    }
}

I don't seem to be able to find the correct WikiPageName, so I need a list of all of the project's Wiki pages to be able to enumerate and retrieve the correct name of the page.


Edit

Here's the requested screenshot:

Release-Übersicht

Here's the URL used:

http://tfs.***.***.loc:8080/tfs/***Collection/******Manager-Plus/_wiki/wikis/******Manager-Plus.wiki?wikiVersion=GBwikiMaster&pagePath=%2FDM%252DRelease%C3%BCbersicht&pageId=6

And this is the value I'm using:

<add key="WikiPageName" value="DM-Releaseübersicht"/>


Solution

  • You can fetch the wikis metadata with the method GetAllWikisAsyc, in the results you will get the wikiIdentifier to use in the method GetPageTestAsync. but you will need the page path, currently you can't fetch the paths with the API, you should manually check it (is the wiki page title) and put it in the method:

    var wikis = client.GetAllWikisAsync("Project").Result.
    using (Stream S = client.GetPageTextAsync("Project", wikis[0].Id, path: "Test").Result)
    {
        using (StreamReader sr = new StreamReader(s))
        {
            string text = sr.ReadToEnd();
        }
    };