通过VSO API在VSO中创建文件夹

时间:2015-11-30 16:00:32

标签: c# azure-devops

我一直在试图弄清楚如何通过VSO api创建查询文件夹,但我始终是“方法不允许”的消息。

我正在使用 Microsoft.TeamFoundationServer.Client 包来连接VSO。 This页面说我需要这个库。我可以查询数据,但似乎缺少创建数据的东西。这个库适合我,因为我有一个WebApi来管理与VSO API的通信。

这是我的代码:

public QueryHierarchyItem CreateFolderAsync(string folderName)
        {

            QueryHierarchyItem newFolder = new QueryHierarchyItem()
            {
                Name = folderName,
                IsFolder = true,
                //Path = "Queries/Shared Queries/" + folderName,
                IsPublic = true
            };

            QueryHierarchyItem item = witClient.CreateQueryAsync(newFolder, _projectName, null).Result;

            return item;

        }

我尝试使用Path属性,但它没有帮助。

  • 我已检查过用户权限。我的用户是“项目管理员”的成员,
  • 权限也设置为管理查询文件夹(单击“共享查询”文件夹旁边的V形符号 - >选择“安全性”)作为组和单个用户。它没有帮助。

我使用免费帐户。奇怪的是,我已经从Visual Studio登录了同一个用户,我可以管理这些文件夹。此功能是否适用于免费帐户?

1 个答案:

答案 0 :(得分:0)

您可以参考MSDN上的此博客了解详情:http://blogs.msdn.com/b/team_foundation/archive/2010/06/16/work-item-tracking-queries-object-model-in-2010.aspx

在这里引用代码:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace QueryAPI
{
    class Program
    {
        private static Project myproject = null;
        public static QueryFolder GetMyQueriesFolder()
        {
            foreach (QueryFolder folder in myproject.QueryHierarchy)
            {
                if (folder.IsPersonal == true)
                    return folder;
            }
            throw new Exception("Cannot find the My Queries folder");
        }

        public static QueryFolder AddNewFolder(string folderName)
        {
            QueryFolder folder = new QueryFolder(folderName, GetMyQueriesFolder());
            myproject.QueryHierarchy.Save();
            return folder;
        }
        static void Main(string[] args)
        {
            TfsTeamProjectCollection coll = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("Your TFS Server URI"));
            WorkItemStore store = new WorkItemStore(coll);
            myproject = store.Projects["Your project name"];
            QueryFolder myNewfolder = AddNewFolder("Your folder name");
        }
    }
}
相关问题